Jump to content

PHP Framework

I have decided to take a dive into PHP frameworks, and decided to try out Mako Framework after looking through the docs and getting a feel for what it offered.

 

Sadly, I have hit a bit of a snag that the docs don't really help me with. If you scroll up a little on this page, you will see the section that talks about parent and child templates.

 

Here is the code I have thus far:

Admin Controller:

<?php
namespace app\controllers;

use mako\http\routing\Controller;
use mako\view\ViewFactory;

class Admin extends Controller
{

public function login(ViewFactory $view)
{
return $view->create('login');
}


}

partials/adminHead.tpl.php:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="{{$__charset__}}">
    <title>{{block:title}}{{endblock}}</title>
    <link rel="stylesheet" type="text/css" href="../assets/css/materialize.css"  />
    <script src="../assets/js/materialize.js"> </script>
</head>

login.tpl.php:

{% extends:'partials.adminHead' %}
{% block:title %} Admin Login - My Blog{% endblock %}

<body>
 <nav>
   <div class="nav-wrapper">
      <div class="col s12" style="margin-left: 20px;">
        <a href="#!" class="brand-logo">Logo</a>
        <ul class="right hide-on-med-and-down" style="margin-ri: 20px">
         <li><a href="sass.html">Sass</a></li>
          <li><a href="badges.html">Components</a></li>
          <li><a href="collapsible.html">JavaScript</a></li>
        </ul>
     </div>
   </div>
 </nav>

The result that I get is {% extends:'partials.adminHead' %} printed out above the rendered HTML, instead of what the docs claim. From the fact that I haven't found anything other than docs in relation to this framework, I am going to assume that it is not very popular, but I hope someone here can help.

 

In case my description of the output was not clear, here is a picture:

JIzfp.png

 

Just in case you want it here is the stackoverflow link: http://stackoverflow.com/questions/37873539/mako-framework-templates

Link to comment
Share on other sites

Link to post
Share on other sites

Shouldn't it be

return $view->create('login')->render();

or

$view = $view->create('login');
return $view->render();

instead

return $view->create('login');

?

Link to comment
Share on other sites

Link to post
Share on other sites

They both do the same thing. From what I can tell, Mako uses its own view rendering system. (Which is why this is so hard to figure out... I only have one set of docs, and no thing else to work with)

Link to comment
Share on other sites

Link to post
Share on other sites

Have you run welcome page before without problems? I mean when you unpack and configure server so it's root dir will be /public, does then site works and displays welcome page?

 

Maybe your installation isn't right

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, Mr_KoKa said:

Have you run welcome page before without problems? I mean when you unpack and configure server so it's root dir will be /public, does then site works and displays welcome page?

 

Maybe your installation isn't right

Yes, the welcome page works fine.

Link to comment
Share on other sites

Link to post
Share on other sites

21 minutes ago, col_crunch said:

Yes, the welcome page works fine.

So templates works, what I did was I created new directory under views called base where I put file base.tpl.php which contains:

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="{{ $__charset__ }}">
		<title>Title of document!</title>		
	</head>
	<body>
	{{block:body}}{{endblock}}
	</body>
</html>

Then in views I edited welcome.tpl.php so it conains:

{% extends:'base.base' %}

{% block:body %}
	Test content.
{% endblock %}

And in result, when I enter / page I have "Test content." displayed with source:

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>Title of document!</title>		
	</head>
	<body>
		Test content.
	</body>
</html>

 

Link to comment
Share on other sites

Link to post
Share on other sites

So, my issue is that no matter what the extends statement is printed, which leads me to believe that there is something wrong with whatever parses the template file.

Link to comment
Share on other sites

Link to post
Share on other sites

Do it on new installation step by step and see where (if) it will get broken.

Link to comment
Share on other sites

Link to post
Share on other sites

So, it works on a new install, but what confuses me is that I did nothing differently.

Link to comment
Share on other sites

Link to post
Share on other sites

You are curious enough you can use program winmerge alike, and hunt for file differences.But it may not be possible for cache.

Link to comment
Share on other sites

Link to post
Share on other sites

I am doing this locally before sending it off to a server.

Link to comment
Share on other sites

Link to post
Share on other sites

I'm just saying you can look for file differences between working version and version that was "ok" but wasn't working.

Link to comment
Share on other sites

Link to post
Share on other sites

I know, I was saying that the cache shouldn't be an issue.

Link to comment
Share on other sites

Link to post
Share on other sites

I'm talking about framework cache, not browser or any else. Framework may cache source code so it will compile templates to php files rather than using tpl.php and maybe even optimize php source files. I don't know how mako framework works. But I'm working with Symfony and it does some of those.

Link to comment
Share on other sites

Link to post
Share on other sites

I just made a new project, no idea what was wrong with the old one.

Link to comment
Share on other sites

Link to post
Share on other sites

Why does everyone consider it a good idea to use as much third-party code as possible?

Write in C.

Link to comment
Share on other sites

Link to post
Share on other sites

5 hours ago, Dat Guy said:

Why does everyone consider it a good idea to use as much third-party code as possible?

Because programmers are lazy.

Why develop your own MVC framework when there are dozens available for free?

Desktop: Intel i9-10850K (R9 3900X died 😢 )| MSI Z490 Tomahawk | RTX 2080 (borrowed from work) - MSI GTX 1080 | 64GB 3600MHz CL16 memory | Corsair H100i (NF-F12 fans) | Samsung 970 EVO 512GB | Intel 665p 2TB | Samsung 830 256GB| 3TB HDD | Corsair 450D | Corsair RM550x | MG279Q

Laptop: Surface Pro 7 (i5, 16GB RAM, 256GB SSD)

Console: PlayStation 4 Pro

Link to comment
Share on other sites

Link to post
Share on other sites

On 19 June 2016 at 10:54 PM, Dat Guy said:

Because I can't debug what I don't know.

Php does get compiled into a redistributable executable, so you always have access to the source code of a php framework.

 

There is this saying:

Dont try to reinvent the wheel

Desktop: Intel i9-10850K (R9 3900X died 😢 )| MSI Z490 Tomahawk | RTX 2080 (borrowed from work) - MSI GTX 1080 | 64GB 3600MHz CL16 memory | Corsair H100i (NF-F12 fans) | Samsung 970 EVO 512GB | Intel 665p 2TB | Samsung 830 256GB| 3TB HDD | Corsair 450D | Corsair RM550x | MG279Q

Laptop: Surface Pro 7 (i5, 16GB RAM, 256GB SSD)

Console: PlayStation 4 Pro

Link to comment
Share on other sites

Link to post
Share on other sites

Have you ever tried to read and understand the (e.g.) Symfony source code? You just can't know.

 

No, you shouldn't reinvent the wheel. But you also shouldn't use monster truck wheels for your bicycle.

Write in C.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×