Compile/PreCache Blade Templates - php

From what I understand when using blade templates, the first time a user requests a page, blade will compile the template and create a cached version in a raw php format and from that point forward will render that page via the cache.
While this is nice, I was wondering if there is a way to precompile templates to the cache before a user hits the page. This allows someone to use a PHP linter on the cached files to see if there are any issues before hand.

You could use BDD or simple PHP script to simulate real visitors, so Laravel could create cached views for you.

Didn't use it myself before, but a possible way could be using the BladeCompiler to manually compile the pages before entering them.
Blade::compile(string $path = null);
https://laravel.com/api/5.2/Illuminate/View/Compilers/BladeCompiler.html#method_compile
Found another person using the compileString method.

Related

Execute php from joomla component on every page

I am learning how to write components in joomla-3.x (currently I'm using 3.6.5) and I'm having difficulties figuring out how to execute my own PHP code on every page. Is that even possible? If so how can it be achieved?
So far, I have been unable to add anything globally to all pages unless I modify joomla's own index.php and I'd rather not edit files outside the scope of my component.
Executing code on every page is probably best done using a plugin or possibly a module.
An advantage of using a module is that you can use menu assignment to select which pages the code should be enabled on.

Some beginner questions about how to port a CRUD application to PhalconPHP

I just started to use PhalconPHP 1.3.1 for an app for my studies' master thesis. Isnt totally developed but I'm working on the CRUD for the moment, so after have some functionality and the UI working I decided to start to introduce this amazing framework. I'm was new on web development, MVC and ORM patterns till I started this thesis. It's first time I use template engines as well. For now I'm successful porting all, but I'm afraid that I'm not doing it in the right way. I started adding my code to the PhalconPHP bootstrap created with the dev tools. Now I start with the questions:
1º- As is a web app that In the future I'll wrap with Phonegapp, I'm using AJAX load function, to don't load all the menu and libraries every time that the id = "content"change. For this I use $('#content').load(); for the content and historyjs functions to change the URL. I didn't do any change to the original code apart of configure on Nginx the clean URLs as
try_files $uri $uri/ /index.php?_url=$uri&$args;
In the documentation shows different way of using AJAX, so I'm afraid that I shouldn't be using this way, breaking somehow the MVC pattern.
2º-Related with this I add to the AJAX dynamically load URL a variable ?header=yes that indicates me to just load the content. So for this in every controller, in the indexActions I do:
$header = filterinput(INPUTGET, 'header');
$this->view->setVar("header",$header);
And after I just check with volt the variable. Is it the right way? I thought to do all with volt but I haven't found how to.
3º-Also, because the menu is common to every page, in the main index.volt(in the folder view) I include the menu depending on the variable. Is it OK as well? Or should I move it to the different views?
4º-Because of 1º, I made my own click functions where I push a new URL and load the content, once again I'm affraid I'm breaking good practices of Phalcon.
5º-The JS/HTML part is in plain code for now, I just replace the PHP part with volt syntax. Should I replace as well code like
<link href="../css/stylefile.css" rel="stylesheet"/>
For its volt syntax?
I would like you to clarify me and give suggestions in case of need of how to change it.
I am using Phalcon and volt at the moment for a commercial project and I find new ways to do things all the time, you have to really try out different methods and see if it works for what you need. if you are looking to work on multiple devices with the same data I would look at the phalcon micro version and use that as a rest api and then create another project which uses the phalcon mvc version to do the client side rendering then use ajax to get the data from your phalcon micro project. This way if you go native mobile, desktop, tv, tablet whatever your needs you don't have to rewrite your code you just need to create a new frontend.
Another thing to look into are partials, you can separate out your header, footer and navigation inside a partial and call them like so:
{{ partial("partials/layout/footer") }}
You also want to look at creating a proper rest api url structure for your phalcon micro project. if you want to get all users you can do something like /users and to get a user by id you can do /users/1 that is very very basic so I have copied in a great article below to give you more information on rest api and a good structure.
You can also set volt variable like so:
$this->view->header = $header;
and call it like so:
{{ header }}
I hope this gives you a little idea, but just try it out and read some articles from different blogs to get an idea what other people are doing, the Phalcon forum and IRC channel is also a really good place to get help
Some good articles and resources
http://inmensosofa.blogspot.co.uk/2011/10/look-into-various-rest-apis.html
http://docs.phalconphp.com/en/latest/reference/micro.html

Calling a view "mid-script" with Codeigniter...can it be done?

I'm using the Codeigniter framework and have tried to stick with the MVC philosophy as best I can. I've recently run into an issue that I'm not entirely sure how to handle.
I have a PHP script running that takes a fairly long time (creating an index for my search engine). What I want to do is have the html show up as it's running.
If I just put echo statements into my controller, and echo every time a document is indexed, it does what I want. I can watch the progress as it happens.
But that doesn't correspond with an MVC philosophy, and I also don't get any of the nice styles and html formatting that is set up for my view classes.
The only way I know to interact with my view is to run the code in the controller, and store the log info into a variable, then pass it to the view when I'm done. But that means I just sit waiting for ages, and finally a big log display shows up (nicely formatted, mind you).
Does anyone know how to do what it is I'm trying to achieve? Use a View, but before the Controller is "done" yet?
You can load multiple view's in a controller, how about loading and displaying a view first and then doing more processing.
There is even the possibility of loading a page (like an outside frame or something) and then using JQuery to load the content that is taking a long time to load.

Caching one section of a CodeIgniter page

I'm using codeigniter to create a web app. I'm creating the drop down menus in the header. These are included on every page using load->view(). To populate the menus some quite complex SQL is used. The contents on the menu will change infrequently (once/twice a week), whereas the rest of the data on the page is constantly changing.
Therefore I don't want the overhead of running this SQL everytime a page is loaded. I looked at using CI caching but its on a page level. I really only want to cache a small segment.
What do you think the best approach to this is? I thought about writing this to a text file, but then you'd have to manually run the code to write this every so often.
Take a look at the query caching page, or alternatively you can use a caching library to cache sections of a page (preferred method IMHO) take a look at KhCache.
Another good caching library I have found is from Phil Sturgeon. http://github.com/philsturgeon/codeigniter-cache
It allows caching models, libraries, or just partial caching like you describe.

CakePHP integration with ExtJS 3

I am a PHP and ExtJS user. I am looking into developing an application using a good PHP framework (CakePHP; good as in "I consider this good for me") and ExtJS version 3. What I would like to achieve is a complete Ext viewport with many grids and functions that would call PHP urls for retrieving data, saving data, edit/remove data (not just for grids, also for treepanel and such). I would like to use CakePHP as backend with all its capabilities for executing these functions. My first goal is to integrate the obAuth component (or any other secure authentification plugin for CakePHP) with an ExtJS 3 login interface. I am searching for the best method of combining these too so that I can easily restrict functions based on the usergroup access. I am thinking of a setup where the logged in user makes one post from Ext regarding the execution of a function and the CakePHP response made present as errors or notifiers through Ext alert boxes.
Do you think this is possible ? Any thoughts of an ideal config for this ?
Thank you.
If you're going back and forth between JavaScript and Cake a lot the first thing you might want to do is override or extend the default View class so it'll package variables you set in the controller automatically into a JSON array or whatever you prefer. That'll save you from having to make a view for each action and/or overriding the layout each time. Study cake/libs/view/view.php and/or cake/libs/view/media.php, you can create custom views in app/views/.
Make use of the RequestHandler Component a lot to reuse logic both for normal views and AJAX.
Beyond that it's normal JS with a PHP backend.
This is actually very easy. First, integrate the obAuth Component into a basic CakePHP install, to see if it works properly and doesn't have any strange quirks. Once that's done, get to work on your frontend.
Your frontend should be designed entirely with ExtJS components. Either design your frontend with ExtJS or via HTML templates, but try not to do both, as it gets confusing and hard to maintain. I recently did this, and every controller action had a view that set up the DOM with some basic elements (a header for the page, any divs I needed to bind components to, and the .js file that was specific to that page/view).
Then, make your application RESTful. All of your ExtJS components can read data from a DataStore (or can just take a URL as the data source), so you just give them the paths you'd like and you're done.
Check out Bancha, it integrates ExtJS 4 and CakePHP 2.
It does this by doing all the communication in the background using an completely implemented Ext.Direct for CakePHP.
cheers
Roland

Categories