I am new to Zend Framework, and i am attempting to remove an action using ZF command line tools. However, i am not able to do so. Basically, there's a function to an action in my controller that i wish to remove. I created the action using the following command:
Action
zf create action name controller-name[=Index] view-included[=1] module
Is there a command to remove it?
There is no command in Zend_Tool for that. You need to do that manually, by removing the action method in the controller and deleting the view script. You have also to edit the .zfproject.xml in the root of your project.
If you remove any controller or action manually, you have to also edit .zfproject.xml file on the root of your project, otherwise it will not allow you to create that controller or action in future again with zend tool.
Go to your application root and edit .zfproject.xml file. This is the file, where zf command will create each controller and action log. remove those actions from there and from controller files and also the views.
Related
Using latest angular-cli, I created new project and everything works fine. Next, I tried to integrate it in Laravel 5.3. I have this project working with systemjs, but I want to switch to webpack and to take advantage of angular-cli.
Problem is that in angular-cli.json I can't specify that index is index.php, it only accepts HTML.
Basically, I can't start the Angular application at all with this setup.
How can I overcome this?
In the end I separated Laravel and Angular 2, as Cristian Sepulveda wrote in the comment. This is the recommended approach anyway.
I make API with Laravel and use it with Angular 2.
In my case I serve the angular app from laravel. I still use webpack to build my assets but have a gulp task which copies the angular index.html to be index.blade.php of which the laravel app serves.
I also use gulp to copy the built files from /dist to /public
I had the same problem and what I found is this related issue in their GitHub issues:
The output folder will always be entirely replaced. You can use the public/ folder to have your index.php which will be copied to your output folder, or output the app to a separate folder and copy the files yourself.
This is by design and will not change. This is a build output folder, not a deploy folder. You should separate those two steps.
So, you can't really achieve what you exactly want, but this is the only workaround I found.
I found only one solution for me.
create build for client side code by ng build --prod
Using gulp copy generated files into Laravel public dir gulp copy (here you can check if old build files exists remove them)
Using gulp-ingect plugin inject copied files into layout gulp inject
-- This can be used in CI and done with automation tools. In result we have inline.js and three *.**.bundle.js files injected. In same main layout i have statically add <base href="/example"> (you can use any defined in Laravel routes root path here) and inside template file which loaded from this path (in my case 'example.blade.php') add angular 2 root element <st-example>Loading...</st-example>
-- By this set up you have root Laravel layout which have inside required by angular 2 root url href and injected scripts files from build. And your template file for current route have root element inside (it included to main layout by simple blade yeild('content')).
P.S. also you must notice that if you are using some http requests in angular 2, after you integrate it into Laravel project this will add csrf protection middleware to each request... And if you have some new errors in requests which work previously just check headers.
Since angular-cli doesn’t allow you to specify index.php, let it be, simply specify index.html then there…
And add an appropriate route into Laravel routing. Like this one, for instance:
Route::any('{path?}', function () {
return File::get(public_path() . '/index.html');
})->where("path", ".+");
Btw, it’s simply a trap for any unknown routes… But I think you get an idea.
I have worked on yii framework before and I had possibility to create module folder and inside this put eg: news module which was included controllers, views and module
I'm new in laravel and trying to create same thing MODULE
i tried the following inside routing
Route::get('/news','/modules/news/controllers/NewsController#index');
file exist but i'm getting
ReflectionException
Class /modules/news/controllers/NewsController does not exist
why ? what i'm doing wrong ?
The Route::get() function is looking for a (auto)loaded Class, not for a file on the disk to load, which is why you're getting these errors.
It's more Laravely (Laravelish?) to include:
Controllers in the /app/controllers/ directory
Views in /app/views/ directory
Models in the /app/models/ directory
And if you are starting out with Laravel, this might be the best way to get started. The autoloader knows where to look for your classes then, and everything gets handled automatically for you.
With the NewsController situated in /app/controllers/ you can do this:
// no need to start the route location with a slash:
Route::get('news', array('uses' => 'NewsController#index'));
You can "package" up functionality using Laravel's Packages, but it would be better to check out the excellent docs and then come back with specific questions..
Put your Laravel controllers in app/controllers, since that directory gets autoloaded, and it is where Laravel expects controllers to be.
Then you can use routes like this (example straight from the docs at http://laravel.com/docs/controllers#basic-controllers)
Route::get('user/{id}', 'UserController#showProfile');
I'm trying to run a controller action from command line. The php code is written in Kohana 3.3. Kohana officially says I have to use minion task processor. How do I include my action in this module?
You can call the minion controller from command line like this (as of Kohana 3.3):
$ php index.php --uri=minion --task={task}
Every task goes inside classes/task, as explained here https://github.com/kohana/minion#writing-your-own-tasks
Make sure to enable the minion module in the bootstrap
Before the minion module, you'd have to use controllers, and some server related stuff would be unavailable, but you would do as in the browser
$ php index.php --uri="control/do/action"
I want to use a function in all models class (in project folder and in plugins folder).
Where should I declare it?
Depending on what your function does, you can create a file in the lib folder and then call it from every where in your app. This is useful in a Symfony project to define common functions (like a toolbox).
For example, in the Jobeet tutorial, they define a method called slugify in /lib/Jobeet.class.php (be sure to name the file with .class.php at the end so Symfony will automatically load it). Then, you can call Jobeet::slugify() every where in your app/model/plugin/view.
This solution works with Symfony 1.4:
You create a new file in which you declare the function you want to be available everywhere.
You load that file with the auto prepend file settingin the php.ini file.
If done correctly, that function is available in all your scripts, regardless of model, plugin or something else from your project.
I'm trying to get my head around the Zend Framework.
I've created a custom route
resources.router.routes.helloworld.route = /helloworld
resources.router.routes.helloworld.defaults.module = default
resources.router.routes.helloworld.defaults.controller = helloworld
resources.router.routes.helloworld.defaults.action = display
In my hellowrold controller class I have changed the indexAction() name to displayAction().
when I try to load the page in a browser I get the following error message:
'script'xxx/display.phtml' not found in path(C:/:blah blah blah)'
What am I doing wrong here?
By default Zend Framework controller actions use the ViewRenderer Controller helper. This helper reads a .phtml file related to the action as the View Script of the related action.
The controller accesses models and in the end passes the result data to view scripts, so view scripts could present the data. This is the "V" in the "MVC" abbreviation.
For your case, you have specified that your default action is named "display" instead of "index".
But I think you have forgotten to create a view script file for this action.
By default the view scripts are located in the APPLICATION_PATH/application/views/scripts directory, with these assumptions:
APPLICATION_PATH is where your application structure and public directory reside in, (for example /var/www/ on Debain Linux or C:\Program Files\Apache Group\Apache\htdocs on Windows).
You are keeping the source code of your application (including your models, controllers, modules, etc.) in the directory called application
If you are having modules in your application and for example your modules are defined in application/modules; then the view/scripts directory is located in each module directory instead of the root of the application structure.
In the above directory, each controller should have a related subdirectory, and each action have a view script file in .phtml extension.
You should create a directory called "helloworld" in there, and then create a file named "display.phtml" in that directory, so the ViewRendere controller helper class could load it and use it as the view of this action.
If you do not want to have a view script, you should prevent the ViewRendere helper from searching for a view script file. to do so, add this code to your action in the controller code:
$this->_helper->viewRenderer->setNoRender(true);
This code tells the view renderer action helper not to search for a view script file.
Please not that all the above are mentioned for a default configured Zend Framework application, but could be changed by configuring your application, resources and helper objects.