How to create router file for a component of joomla. I am using Sef
url in particular
I was having the same issue and after trawling through the internet and only ever coming across answers like the one seen here ("see the documentation") which is really unhelpful in my opinion and of all the documentation that page is the most unhelpful.
Anyway I firstly ended up giving up on the "component router", I could get it to easily work to build routes but found that it wouldn't parse anything and without having both working, it was pointless continuing.
In the end I decided going down the plugin path was the answer and found this really good plugin here from Daniel Calviño Sánchez.
I then ended up finally coming across some joomla documentation here that IS perfect and will get you exactly where you need to go.
I personally think that the joomla router needs alot of work and saw there are lots of ideas from people wanting it upgraded. I found using a plugin in the end was the easiest path and was the better solution all round.
I would be happy to discuss with anyone as to why my component router wouldn't call its parse method as if that actually worked, it would've been my first choice.
Hope this helps.
Unfortunately documentation didn't provide a way to register my router so I found an alternative solution.
The router.php is actually a Joomla\CMS\Router\SiteRouter
You can use the $this variable, even if you think you're not within a class.
This can be checked by performing var_dump($this)
There are two methods that can be used.
$this->attachBuildRule(function(){
// build rule code
});
$this->attachParseRule(function(){
// parse rule code
});
If you are using an object implementing RouterInterface the callbacks are the following
$this->attachBuildRule([$myRouter, 'build']);
$this->attachParseRule([$myRouter, 'parse']);
The methods expect a callable and a STAGE, see Router::PROCESS_* constants in namespace Joomla\CMS\Router
If you are using PHPStorm you can write the following code for assistance:
/**
* #var $this Joomla\CMS\Router\SiteRouter
*/
Check out this documentation .
It describes very precisely how to create a Route and how the Routing works in Joomla.
Also check out com_content/router.php as an example
Related
I want to add my own oauth provider. After reading this, I added a PhabricatorFoobarAuthProvider.php in phabricator/src/applications/auth/provider/ and added a PhutilFoobarAuthAdapter.php in libphutil/src/auth/ and then executed arc liberate seprately. I expected to see Foobar provider to show in this page: localhost/auth/config/new but I didn't. What need I do to reach the goal? Am I forgetting some steps? Thanks.
I use `install_ubuntu.sh` to install phabricator. The layout is like this:
phab
....install_ubunut.sh
....arcanist/
....libphutil/
....phabricator/
So the english is a tiny bit broken but i'll answer this the best that I can. What I assume you are trying to do is figure out is "how can I add my own Oauth provider?". In doing so you came across this magical function that seems to be doing something but your not sure what.
The PhutilClassMapQuery is essential to understanding phabricator and arcanist. If you grep -R "PhutilClassMapQuery" . you will find around 100 different places that it is used. Every place that this is used you as the user are able to load in your own classes that integrate seamlessly with the Phabricator application.
I'll use PhabricatorAuthProvider as an example. If you look here you will notice that this is an abstract class. What the that function does is say load in every class that extends the current class of PhabricatorAuthProvider. So as an example if you look here you can see that this class provides Persona authentication and it does that simply by implementing the needed functions.
I am not going to go through the rest of this but you should be able to figure out the rest based on the above and using this link which shows you how to load your classes into Phabricator.
Hope you enjoy. Phabricator is some of the nicest PHP code that you will find.
First question on StackOverflow (I don't know if I'm doing this right, so sorry if I mess it up)
Background:
My controller has a method that list all actions in my app and plugins called getActions().
And I need to use getActions() in a Helper that overrides HtmlHelper->link() method, because the purpose of this method is return null if the link is forbidden by Acl, thus not rendering any link that would lead to a forbidden action.
Question
How to share this method? I'm doing this wrong?
Lib is the right way to go?
This doesn't seem right: In CakePHP, how do I call an AppController method from a helper?
Don't share the method, share its output. as mentioned in the link to the other question.
I assume that this data is static, meaning: if it will be called from any part in the application, it will return the same value.
Call the method in the controller, store its output in a view-variable or in the session, and write a helper that will access this information and do the acl logic.
It won't break the MVC and will avoid DRY.
The right place for the method is Lib, because its a general purpose method that is going to be used in differents places with differents objectives.
CakePHP's core has many examples of this approach like: CakeTime, CakeNumber and others.
Others examples could be seen in some of CakeDC plugins too.
IMHO #yossi was right about "assuming the data as static", but his approach of storing the data in Session just would make my code more confusing.
In my particular case I'm taking the Lib way. Thanks for the help.
In this stackoverflow post,
Get the query executed in Laravel 3/4
Ricardo Rossi provided a great answer about using Kint and a custom class to easily output information about a Laravel query created using the query builder.
I was able to setup Kent using composer but am new to Laravel and haven't used PHP since version 4.
Could someone please provide an example describing how to create a class which can then be called from anywhere. In his example, Ricardo says he uses "DBH::q()".
At the moment, I'm stuck requiring common files just like in good old PHP4 days.
Thanks
You likely want to use psr-0 auto loading with a namespaced class. Here's a post on setting up laravel which says how to do that.
If I understand your question correctly you are asking how to go about using the following syntax DB::q() using your own custom class...
Laravel uses Facades throughout its design which enables you to access classes from anywhere in your app using static style syntax (e.g. Input::get() or Route::get()). I note Fideloper has also provided an answer to your question... He has an excellent tutorial about how to wrap your own custom class in a Facade so you can use this syntax for your own classes and also sidestep the need to inject the dependency in any class that uses it (i.e. once set up correctly it can be called upon anywhere in your app).
Fideloper tutorial is here...
Hope that helps - Good luck
I've recently started to learn Symfony2, based on a job opportunity. I've got some of the basics down, but I'm strugging with the #template() section of annotation routing.
I've been able to use annotations to route the right url to the right controller method, but the template I put in #template() never seem to work.
Basically, what I'm after is an explanation of what goes into it. I've seen in the official documentation:
#Template("SensioBlogBundle:Post:show.html.twig")
But I don't understand what that param is. I get the ending part is literally a filename, but what are the first two components separated by colons? I've tried a bunch of different things to try and understand, but I haven't been able to make it connect to a new template file I've placed in views/main/index.html.twig of my bundle's resources. I've tried
#Template("BlogBundle:main:index.html.twig")
With no success. (BlogBundle is the folder all my code resides in, within my bundle)
The rest of the documentation seems to make sense, it's just this one param never seems to get a good explanation.
Thank you.
SensioBlogBundle:Post:show.html.twig mean this path: src/Sensio/BlogBundle/Resources/views/Post/show.html.twig
The bundle:controller:view is Symfony2 standard notation and, in case of template or render of views, have to be interpretated as I explain.
I'm a big enthusiast about new Zend Framework. I had done one project in the previous version so far and I decided to learn new one which contains a really hard parts to understand for me.
I've watched webinars and youtube videos, also I read the documentation and I'm trying to understand this framework simply by read the code but there are few things I just can't figure out.
There is a lot information about EventManager in webinars but since I'm lack at English I'm just not able to understand 100% of the speech.
I know that event manager manage events which is quite obvious but I don't really know how to use it: in one of the webinars they provide some simple examples but they don't explain where to put this code, is it module.php file? Or some other place if you can show me some practical example with explanation so i can see whats the point.
Next thing is that mysterious $e passed as an argument to most of the functions in Module.php which after is used like this: $e->getApplication or something I just wonder what this $e stands for? It is instance of what? And next thing is how it is passed "automatically" to these functions?
Another problem: in configuration files which are specified for each module called module.config.php there is a lot of things. I got the point of routes I've understood them but I can't figure out what are the invokables and factories. It is also explained in one of the webinars as follow: invokables are paths to classes, factories are callable functions or classes (cant remember). The point is OK, that make sense in some theoretical talk but please provide me some examples with in depth explanation, where those factories and invokables come from and other stuff that I need to know.
The other thing is that there is a lot of configuration possibilities in those configuration files. Where can I find some informations about what "keys"=>"values" are possible in those files?
That's all for now but there are still unanswered questions i would like to ask. If someone is able to help me, I would really appreciate to correspond via mail with this person.
Ok one problem is solved. The one about mysterious &e so if somene is intersted in here is a solution:
This $e variable instance depends on what function we use in module.php file:
case 1: init() -> &e is an instance of module manager
case 2: onBootstrap() -> &e is an instance of MvcEvent
(if there are other cases i havent found please let us know)
The thing is that those methods are called when event has been triggered so mysterious &e is passed to those functions by listenerers which are listening if these functions appears in our code (this is my simple logic of that so please dont hate me)
There are still other questions to answer.. as soon as ill figure out some senseful answer i will let you know
Within stock ZF2 code, $e is always an instance of Zend\EventManager\EventManagerInterface. Usually it is either an Zend\EventManager\Event or an Zend\Mvc\MvcEvent.
A class' EventManager triggers an event which results in listener callbacks being called. Each listener callback is passed an instance of an Event which then has some useful methods, notably getTarget() and getParams(). Other instances of EventManagerInterface usually have more specialised methods. MvcEvent in particular has methods related to the Mvc component, such as getApplication(), getRouter(), getRequest() and getResponse().
You can find more information about tghe EventManager, application configuration and MvcEvent in the "Using Zend Framework 2" book: http://leanpub.com/using-zend-framework-2