Jump to content

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
https://linustechtips.com/topic/612719-php-framework/
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
https://linustechtips.com/topic/612719-php-framework/#findComment-7922219
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
https://linustechtips.com/topic/612719-php-framework/#findComment-7922340
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
https://linustechtips.com/topic/612719-php-framework/#findComment-7922698
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
https://linustechtips.com/topic/612719-php-framework/#findComment-7928483
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
https://linustechtips.com/topic/612719-php-framework/#findComment-7936536
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

×