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.
Related
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.
I have a custom library that we will call library1. I'm trying to extended library1 with another custom library called library2.
I could do a require_once and include library1 in library2. The other option would be to have library2 use codeigniters load method and load library1 from inside library2.
Any one have any thoughts on why one way is better than the other?
I stumbled onto this problem recently, and for me using require_once proved to be a simple and efficient solution.
First of all, "oop"? I think you are seriously missing the point of mcv, secondly check this here
"CodeIgniter’s Hooks feature provides a means to tap into and modify the inner workings of the framework without hacking the core files. When CodeIgniter runs it follows a specific execution process, diagramed in the Application Flow page. There may be instances, however, where you’d like to cause some action to take place at a particular stage in the execution process. For example, you might want to run a script right before your controllers get loaded, or right after, or you might want to trigger one of your own scripts in some other location."
I am trying to integrate to a joomla project, a list of php pages setup that update their content from db, and give select options to the user, to navigate through this content. Select is also dynamic. All dynamic features work with url parsing.
For example, pageone.php gets some data from db and creates a list of selectable links to page2.php?data=fetcheddata. Page 2 gets url variables and performs queries to db to select the data.
How am I going to integrate this to Joomla? Should I make a module to include the basic php page, and how url parsing will then work? Should I make an i-frame wrapper? Please enlighten me..
You just described the way Joomla works. Depending on the content you want to present, there may already be an extension that does that, or at least does something close that can be modified. Without any more details it is hard to say, but what you are describing could probably be accomplished with a CCK http://extensions.joomla.org/extensions/news-production/content-construction. You could definitely do it with a combination of Chronoforms and Chrono Connectivity -
http://extensions.joomla.org/extensions/contacts-and-feedback/forms/1508
http://extensions.joomla.org/extensions/directory-a-documentation/faq/5661
If not, then you will probably need to code a component - http://docs.joomla.org/Developing_a_Model-View-Controller_Component_-_Part_1
1) iframe solution is the easiest one. But it has its limitations...
2) you can write Joomla component (not a module) that will do the job, but I'm afraid in this case you will either have to switch to Joomla URL format... unless you find some trick how to workaround that.
If your site is not very complex a simple approach is to write your application in plain php, and integrate your Joomla template to your application so your visitors can't tell any difference. Then, you will place links from your Joomla to your application and vice-versa accordingly.
However, the best approach if you are more familiar with Joomla is to develop a component. Here you can understand the difference between Joomla Components, Modules and Plugins. Please read Joomla documentation for further understanding:
http://docs.joomla.org/Extension
http://docs.joomla.org/Component
Another day playing around with joomla, and another shortcoming to fix :)
This time it comes in the form of the administration(backend) menu.
To add items/subitems to this menu, people have to write the menu items in an xml file accompanying their components/extension/plugin/whatever.
When the extension is installed, joomla "generates" the menu items and "stores" them in the DB.
Effectively, the real/tangible menu is rendered by reading the DB.
This has several implications:
The menu is not scriptable
The menu is not dynamic; changing the XML file after installation, won't update the menu
Removal of items is not scriptable; joomla takes care of removing any items when you uninstall the extension.
I've got this system which relies on the ability to modify menu items on the fly, but through code.
Simply put, I need to have functionality where I can create a volatile menu item (ie, it gets removed at the end of session).
To do so, I've got a couple of prospective hacks:
Override the joomla global database instance so that I can make it return fake menu items. This is possible since the database object is stored in a public property of JFactory class: JFactory::$database=new MyFakeJDatabase(JFactory::$database);
Intercept the menu code (html) before being output and mess it up according to my needs. This is not template-friendly in that the end result would be injecting html, which might not be what the template was designed for.
Create menu items through javascript. This suffers issues with the template AND the javascript that toggles submenus.
Create menu items in the DB whenever I need them and somehow "tag" my items so that I remove them the next time (or end of session). This sounds like it would work like a charm. Since I can buffer menu items, I could possibly create my menu items in one whole SQL statement. Than I could use another SQL to remove the tagged menu items. 2 SQL statements might not be much of a load on the server.
What do you think?
Edit: I've checked joomla/administrator/modules/mod_menu/helper.php to see if I could find a way to inject my stuff, wishing that maybe joomla used a global variable or something, but to no use - the menu items are creating directly by reading the db and rendering as well.
FYI I've searched a while on Google, to no use.
Interesting. I have worked with Joomla for many years, writing all kinds of extensions for various purposes, including integrating external systems. It has been my experience to approach these types of situations by looking at the basic needs of code execution. And I always seem to start off asking: is it UI driven or system-driven?
First, consider if the code will execute according to user-generated system events. There are a whole bunch of 'em and you can even trigger your own. If this is a requirement, then the solution will need to incorporate a plugin, attached to events.
However, for any kind of dynamic UI content, you will need a module. Modules are all about displaying content. These guys are designed for the user experience. So, consider how access to the UI content will be managed. Which users will comprise the "audience" of this content? This is controlled by user groups and access levels. At some point in your code, preferably early, you will have to check the user's rights and then modify your code execution in response. Thankfully, I find that someone has already done a lot of the work for me. How?
Find an extension that performs the things that your code needs to do, or as close as one might match up. The entire CMS is built with extensions running atop the Joomla! Framework and there are thousands of extensions available for download. Once you've found it, clone the thing. Then edit it so that it does what you need it to do, plus what it did before (if that is a requirement). Install your updated clone, unpublish the original and publish yours. Saves a lot of time.
Looking at your requirements, the code only executes as long as there is a session. I would start with with a 'user' type plugin. When the user triggers a login event the plugin can add the dynamic menu records to a session variable as an array of db records. When the user triggers a logout or the session times-out, the records will go away by themselves. Then I would simply clone "mod_menu" and have read in any records that it finds in the users session. I use this session variable technique all the time, especially when implementing analytic data gathering stuff.
Anyway, I don't post often; but I sure hope this helps. I would love to see this type pf functionality myself. Just haven't the time to code it.
Good luck!
chozyn
The "correct" way would be to write a module which overrides the core menu module to achieve the old functionality with the added feature of dynamic menus from whatever source you have. Not particularly a nice way to go, but that is Joomla's way.
Thanks to #ircmaxell to point this method out.
No hack seems satifactory, safe or maintainable enough to achieve this.
I've aborted the project and instead am putting buttons in the main dashboard through JS.
It's highly inconvenient to end users (they still miss sub-items). But what the hell...it's Joomla's fault.
Oh and for the record, I needed to add my own custom "pages" similar to admin components. Guess what? That failed as well, so it's another hack.
Hope that by version 1.7, they[joomla] trash the initial codebase altogether.
Alright, I have a wordpress site, that I want to have a clientportal built with codeigniter in it. For the sake of continued theme, I would like to have the codeigniter program where the page/text would normally be.
Here is the site http://foretruss.com/wordpress/?page_id=8 you can see the error I get when I have php_exec plugin installed and use the snippet.
Any Idea's/help/word of advice?
It's a bad idea to mix and match frameworks like Wordpress and CodeIgniter. There are bound to be collisions of variables and constants; not to mention the substantial increase in resources required to load the page.
If you REALLY need to do this, though, you can try loading your CI setup into a separate directory from your WP setup and use AHAH or an iframe to pull everything over. Granted, you won't get the SEO benefits, but at the same time it's probably the "best" way to go.
For the record, the error that you're getting from CI is a header error. Basically, it's trying to put something in your cookies or write to the HTTP request headers, except they've already been signed, sealed, and delivered (hence the error). Perhaps if you turn off sessions in CI, you'll have better luck. The alternative is to load up the index.php file for WP and put a big
ob_start();
right at the beginning.
See another post on combining CI and WP: Getting posts from Wordpress to out of WP in codeigniter view