Where to place calls to route() within Package's Service Provider? - laravel

I have 2 Laravel packages; one for managing an admin panel. And the second one for filling it with useful pages.
Now the first package; let's call it AdminPackage from now on. Has a built in Menu Manager which allows me to register new headers & menu links from outside of the package.
The idea is that in my second package, which adds functionality to the first, can call the AdminPackage::menu()->addHeader() and the AdminPackage::menu()->addLink() methods to add some links to the navigation of the admin panel.
But now comes the problem:
When I call the method in my 2nd package's Service Provider I get the following error:
InvalidArgumentException
Route [route-name] not defined.
I have also tried putting the code directly in the Service I'm binding to the IoC container within my ServiceProvider. But same problem.
I get the error using it in both the boot() and register() method. So the routes have not been fully loaded at this point in time.
How can I solve this problem? I need to wait for the routes to finish loading and call the menu manager methods before the page is rendered and the menu items are displayed.
Thanks in advance!

Related

Laravel 5.1 UrlGenerator route not defined error

I have an app built with Laravel 5.1. I'm using Form::open using a route_name to generate the url to post the form to as well as creating links by defining route and using the UrlGenerator. The issue is that I have some buttons/links created for display purposes and do not have pages created yet.
I get a route not defined error with stack trace going back to UrlGenerator line 296. I'm wanting to set up something so that the error does not display. Instead, I would like a link to be generated to the pre-defined page that I have created saying that the feature the user clicked on is not yet developed.
I thought about doing something similar to a 404 error, but the issue is that the existing page (the page the link or button lives on) is not being displayed, not just that route is missing.
For example, below, I create a link to the route "broker_contact_create" Since this route does not exist, the page displaying the link will not load. Instead, I get the error saying:
ErrorException in UrlGenerator.php line 296: Route
[broker_contacts_create] not defined. (View:
index.blade.php)
<div class="col-md-6 col-lg-7 margin-bottom-15">
+ Add Contact
</div>
Instead, I want the page to be displayed. When the user clicks on the link to a missing route, to have them routed to a page that tells the user they clicked on a link to a feature that has not been enabled yet.
So basically I just want it to do: if route not found then provide $url.
If you follow the stack trace, you'll see that the route function basically invokes UrlGenerator->route
https://github.com/laravel/framework/blob/5.1/src/Illuminate/Routing/UrlGenerator.php#L300
Which checks if the route with that name exists, and if not, throws an InvalidArgumentException.
Basically, what you're trying to do is not possible. You must define that route if you want to use the route function.
I think your best option is to set up a "feature not developed" view, and point all of these pending routes to that view. That way you can use the route function. Your link/button will be generated, but will take them to a "not yet developed" page. Another benefit to this is that all of your routes are laid out and you can easily see which ones need to be developed.
Route::get('/brokers/contacts/create', ['uses' => 'HomeController#notDeveloped', 'as' => 'broker_contact_create']);
And inside your HomeController:
public function notDeveloped() {
return view('pages.not_developed');
}

Broadleaf - Extending DemoSite Admin - Add new Menu and Page

I have been looking into Broadleaf since last couple of days. I have managed to run it on local tomcat with MySql. I have extended Entity for my custom requirement following Broadleaf's documentation.
Now I want to add a menu option (in left menu) in admin. I have no clue from where Broadleaf admin site displays the web page. How left menu is displayed ? How data from controller are binding with view ?
For example, if you access product page in broadleaf admin section, then URL will be http://localhost:8081/admin/product/. Following it I managed to know that it calls AdminProductController.java of framework's admin module. I looked at the code of AdminProductController.java but didn't get a clue how data is being forwarded to view. Also didn't find the product jsp/template/html.
I guess admin module is using EntityForm.java for view. If I intend to use simple jstl then is it possible?
My question how easily I can extend admin of Heat Clinic demo site to add new pages, menu items etc? If anyone has customized/extended demosite admin then please suggest.
We have some docs on how to do this at http://www.broadleafcommerce.com/docs/core/current/broadleaf-concepts/admin/admin-custom-controllers. The bottom line here is that if you want to add a new page then you can simply use normal Spring MVC as you would on the frontend. The only difference is that there are some specific ways to place new template files (which is documented on that page).
To answer your question, most URLs in the admin are handled dynamically by the AdminBasicEntityController. Most of the sections are handled generically by this controller but there are still certain instances where we needed to override things specifically, like with AdminProductController.
Also, the admin is built with Thymeleaf and not JSPs so if you want to add more pages they will need to be done with Thymeleaf.

Prestashop module admin panel with custom view

I need to know how to create a module on Prestashop with a custom view on admin. The documentation is very poor and I don't understand how to call a view with parameters passed by the controller. I'm using Prestashop version 1.6.
I already did these steps:
Created XML.
Created controller with constructor and install/uninstall.
Created table on DB and class.
Linked on admin menu my module.
When I go to my tab on admin panel I see a table with my db data. I need to load a custom tpl file where I can customize completely my page.
I have read so many guides and documentation (ufficial or not) but nothing clear.
Just follow the HTML and CSS in getCOntent() function in your main php file.
Whatever HTML and CSS return getContent() function will be view of your module in admin panel.
Just concentrate in getContent function of other existing module and you will get what you want.
I f you want to load a separate view than create it separate and load it in getContent() function.

Magento - First class / method

I would like to add a registry item at the very start of the all the front-end (and maybe admin) page calls (any kind catalogue, cms, controllers, etc). I want to add:
$myRegistry = new stdClass();
Mage::register('myRegistry',$myRegistry);
Which is the best class / method to overriding?
Ie which class / method is executed for every front-end call (and possibly admin too)?
You can create an observer for the controller_action_predispatch event, that will run before any page is built.
If you need help creating an observer, you can find information on that here: http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/customizing_magento_using_event-observer_method

Joomla registration override

I would like to override my joomla registration component in the way to have next to it the login form as well. As first step I made in my template folder the registration call but from here I don't know how to include the login form.
thanks
fefe
Is this roughly the idea you're looking for?
http://zebiangroup.markmurphy.ca/component/users/?view=login
If so, I'll be packaging it up as an extension shortly. If you need it asap leave me a message at markmurphy.ca and I'll get in touch.
I'll be back to update this post when I have the extension finished and uploaded.
[Edit:]
I'd hate to leave you totally in the dark and keep you searching for an answer so I'll point you in the right direction.
I was able to write a system plug-in that overrides the user components' controller.php only if that component was the one being requested and if the requested view was for the login or registration and if the task was only to display.
From there I had the new controller.php override the requested view name substituting my own and adding the appropriate models, references and variables to the view.
After that all I had to do was add the layout to my active themes "html" folder under com_users.

Resources