ZendFramework Headscript Helper - Make scripts unique - php

How can I ensure that the headScript and headStyle helper include css files only once when added?
The reason I am asking is that I would like to display some contents in a lightbox and all Flashmassages.E.g. notifications like profile successfully edited.
To display flashmessages in the lightbox i would like to check at the top of my layout script if they are set, in case they are i would like to attach the required javascript library using the headScript helper.
The problem is that I have no control about the scripts which were already added at this point. Maybe at a page where the library is needed for an other use case, it has already been added with addScript.
How can I ensure all scripts are added only once to my helper?
I already checked that these helpers extend Zend_View_Helper_Placeholder_Container_Standalone which uses an ArrayObject internally to hold the data and provides getters & setter to the array object.
Maybe a solution here would be to check each time when adding a script file if it already exists using the ArrayObject?

As long as the paths and filenames are the same, the files will only be added once. The Zend View Helpers should take care of that for you.

Related

Can I include php file in .tpl?

Can I include a php file to tpl?
All I need is data from the database. I tried with required('path/file.php') but without success.
I already have controller for that. I need to include controller/file, class/php extension anything just need in tpl. I use OpenCart version 2.3.
if you need data from the database, in MVC a model should be used, and then let the controller add it's data to the $data array, which the is available to the template.
this shows how OpenCart actually works (source):
now tell me how your attempt to change a template (view) fits into there (notice the vertical lines).
just load the model into the controller and add results to $data, then it's available in the template.
You should not directly mix templates with custom PHP code, even if in some template engines it's possible.
You should rather look into means of providing your PHP logic through functions, filters or macros. This way you make your PHP code available in templates.
If OpenCart uses twig, you could look into how to do such in the documentation about extending twig here.

Pass Variables to Included PHP file inside a Joomla Article

I'm new to Joomla, but not a new programmer. I've written several applications in PHP that I want to include inside Joomla articles. Simple enough:
<?php include 'file.php'; ?>
The issue is that inside the PHP files I have a bunch of code gathering and creating variables that I need to POST and retrieve. I can get those POST variables inside the Article, but I can't pass them back to the included PHP file.
I've even coded the included PHP files to access the Joomla framework hoping to retrieve Joomla user id for example. This won't run inside the Article either and returns empty. However, if I run the PHP file on its own outside of the Article, I can access all POST data (obviously) and also the Joomla JFactory data. So it runs fine, until it's placed as an included file inside an Article.
The only way I've been able to pass something to the included PHP file is using $_GET url variables like this:
<?php include 'file.php?data=something'; ?>
However, this simply isn't practical as I have too many variables to pass like this. Normally, included PHP files run as part of the parent script and have access to all variables. How can I accomplish this in Joomla??
Much appreciated!
It is not recommended to include php into articles. Try instead one of these approaches:
Load your code in the index.php - file in your template: /templates/yourtemplate/index.php. This file is called every time your page is called.
Make a template override of the component where you want you external php file to be loaded. If this is in an article, you copy /components/com_content/views/article/tmpl/default.php (and possibly also other files there) to /templates/yourtemplate/html/com_content/article. Then add your include-statement here. (info) This file will be loaded each time you view a single article, but you can have further logic to only run it if (whatever)...
Use Jobin Jose's approach if you want to load you php-file inside content in an article. (info)
Some other approach writing a plugin
...or a component
I would say probably the easiest method is 2. (or 1.), but it all depends what you want to do.
Try this,
You have to create a simple module for your requirement, means what you are trying to achieve with included php file.
then place that module within the article with {loadposition module_position}
then you will get all the POST variables to that article and also suppose user_id and all other joomla Factory can be accessed bcoz its a Joomla module.
for a quick tutorial about module creation can be found here.
hope it make sense.
I resolved this using an Extension called Sourcerer
https://www.nonumber.nl/extensions/sourcerer
Variables can be passed without issue now.
Thanks for the input.
Why do not you try to create a new Joomla component and do whatever you want it it?
I am absolutely beginner in php/mysql but managed to do it with my page, following this instructions:
http://www.inmotionhosting.com/support/edu/joomla-3/create-component/helloworld
When you create this component, whatever you write in its "default.php" file, is actually a blank HTML/PHP page, with your joomla design and some other Joomla-features.
Sorry for the amateur answer and terminology :)

PHP Form builder class working with old version of bootstrap?

I am using the php form builder class (http://www.imavex.com/pfbc3.x-php5/examples/html5.php)
and jqbootstrapvalidation (http://reactiveraven.github.io/jqBootstrapValidation/)
So far I can succesfully combine these (even using some of the patterns php form builder class already built in) and I edited some of the element php files to change a pattern here and there, and to add some \n's to make a readable source code. (I still don't like my entire form on a single line in the source..)
But I would like to use different colours for the bootstrap. I've tried downloading several themed bootstrap.min.css files using paintstrapand twitter bootstrap themeroller
However, as soon as I include these instead of the standard netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css file, all my styling is lost and it looks the same as if there was no stylesheet included.
Since the php form builder class is relatively old, do I need to change all it's code to become compatible with the newer bootstrap, or is there a faster way to do this (perhaps a different form builder?)? Or am I messing up something else that is causing this change style options?
Appearantly there are a few changes need to make to fix this:
https://code.google.com/p/php-form-builder-class/issues/detail?id=205
allthough it is not "full-on" bootstrap 3.0. Also, the jqueryvalidator needs some adaptation to work with bootstrap 3.0. I'm currently busy making everything work the way I like it, adding glyphicons for the forms (optionally) etcetera. I'll get back to you as soon as I am finished and drop the code of somewhere for all the lovely people to enjoy or shout at.
I did'nt want to use imavex class for several reasons :
wanted a class witch could be easily updated if Bootstrap's version changed
wanted to have more control on generated code (add or remove wrappers, class, attributes, ...)
wanted to generate separate code for css/js includes/js code
wanted to be able to configure any jquery plugin with it
So I made my own (not free but only 5$), you can see the demo and complete doc here : http://codecanyon.net/item/php-form-class-for-bootstrap/8790160?WT.ac=category_thumb&WT.z_author=migli
Hope it helps and hope you'll like it

Reading PHP file with fread

I am working on cake php.
I want to develop a generalized application in which i will give in folder names.
Those folders will be basically the links of other application, also on cake php.
Now the main objective is that my app will go inside the controllers' folder and first list out all the controllers, and then look inside that controller and read each inside function, and show them as separate functions.
I used fread and file_get_content,
but they are not reading properly even the string which is returned as file contents has some text missing from start.
Adding to that i remove the starting php tags from controllers it reads whole file but the thing is in this way the controller wont work.
anyone having solution of this please ?
You could use Folder class from CakePHP core or even DirectoryIterator to get a list with all of your controllers. Then instead read the content of your files you could use ReflectionClass to collect information about your classes. ReflectionClass::getMethods() can help you to build your methods list. You could also consider just the public methods if desired making use of ReflectionMethod::isPublic() method.
Depending on your implementation you'll have to load the controller classes

CakePHP: Embed CTP filename and path in views and elements

I'm looking for an elegant way to make a bit of jquery aware of the filename and path of the ctp file containing a given dom selection. I'm using simple_html_dom to write changes to template flies via an ajax call. I need to provide the filename and path of the view or element template ctp file that contains the dom element I've selected in order to write changes to the correct file.
Outside of manually passing this information into each and every view and element in my application, is there an elegant (and secure) way to make this information available to jquery?
Additionally, is there any reason I should be worried about embedding this information in the document in plain text? What is the most appropriate location to store it? My first thought was in an element's title attribute, but is there a more appropriate location?
Thanks!
UPDATE This question may be better posed as: what is the best way to transparently extend or modify every view and element in cake? I'm passing some information down from app_controler in beforeRender now, but that doesn't allow me to pass information about individual element view files as far as I'm aware. Ideally, every view and element would look for the presence of a certain classname in dom elements and insert path and filename information in the title attribute for that element before rendering. I can't figure out a good way to do this!
<div rel="<?php echo __FILE__; ?>">...</div>
unless im not understanding you
You could create your own View class that handled this for you. Inside your 'views' folder, create a file named (for example): custom.php.
This file should contain the class that extends the base View class of CakePHP, named 'CustomView'. Then, in your AppController's beforeFilter, set $this->view = 'Custom'. I'm not sure which method would be best suited to what you want to do, but render() or renderLayout() are probably a good place to start looking.

Categories