Strange Zend issue with action - php

I got a system written in Zend Framework and Bootstrap. It is working properly in a server but I need to put it in another server.
I got a section to articles but when I try to open some article in this new server it show the error:
Message: Action "NameOfMyArticleTest" does not exist and was not trapped in __call(),
This is really weird because in the old server it works properly and the code is the same.

Sounds like a routing problem.
The __call() method is triggered if Zend isn't able to find any appropriate methods in the controller.
Your routing is looking for a NameOfMyArticleTestAction method in the Articles (?) controller class.
olddomain.com/articles/name-of-article-test was routed to the correct method in the Articles class, just should see and check whether the domainname has any influence on this routing.
Good luck.
Oh, P.S.
You can check the bootstrap version in one of the .css files, the file starts with something like
/*!
* Bootstrap v3.2.0 (http://getbootstrap.com)
* etc.
*/

Related

Symfony only showing "symfony has been installed" on remote server

So, school has given me this domain which includes quite a lot of program possibilities including symfony, I decided to try and get my website, made in symfony on there, but I can't get the routing to work since it only shows me a message saying that symfony has been installed successfully, I've ran out of options myself, I haven't tried a lot, since I don't know a lot about it, hence the question here.
TL:DR
Symfony only shows the "installed successfully" on remote server (hosted by Neostrada) I'm hoping someone here can help me out.
EDIT: here's a screenshot of the message:
First, I'll post this link here...
read the note at the end of the answer first
Now. I don't know if you know what MVC is, but shortly, it's a structure called Model-View-Controller where the user first contacts the Controller, in symfony also called an Action, which picks an appropriate action function, geatheres Models (via communicating with the database and all that magic) and then sends the whole package to the View (in symfony created in Twig templating framework).
The file structure is made like so:
app //contains main server files
- cache //contains production and dev files, you won't pay much attention to this.
- config //This is where you find the routing.yml, paremeters.yml and other config files
- logs //git logs and other goodies
- Resources //This is where your views are found
bin //Doctrine and goodies, don't pay much attention here for now...
src //This is where the bundles (controllers) are found
- AppBundle //You should get this bundle by default
- Controller //This is where you put your controllers - they have to have a Controller.php sufix (UserController.php)
- Models, Enteties and other folders you want to put in //All custom folders
- YourCustomBundle (note that both are ending with Bundle)
web //This is where you put your css, js etc. files (in js/, css/... subfolders)
Now, if you go to the HomeController in src/AppBundle/Controller. In there you'll see indexAction function. This one triggers the main, index page.
Note the namespace, usings and what the controller class is extending. If you create another action called, for instance myCustomAction(Request $request), you'll create an action ready to take in orders. But from where? Go to app/config/routing.yml, you'll probably see something like:
app:
resource: "#AppBundle/Controller/"
type: annotation
Above it add:
page:
path: "/"
defaults: { _controller: AppBundle:Home:myCustom }
//note that I first called the bundle (AppBundle, then the HomeController (without the
//Controller part), then the action (no Action part neither)
Now you got yourself a path to your action! Now simply return a view in the controller (look at the indexAction), should be something like:
$this->render('home/mycustom.html.twig');
in the myCustomAction function. After that create a mycustom.html.twig file in the app/Resources/views/home/ folder and that's your view. Note that Twig has a bit different syntax than PHP.
note: I highly suggest you learn from the official symfony website. This is all TL/DR (too long, didn't read) style of writing. It's explained a lot better there with details into why you're doing something. What I wrote might or might not work for you, because of the speed in which I explained the concept! Also if you're not familiar with MVC, I suggest you learn the logic behind it first, before rushing into Symfony.

Symfony2 #template() Misunderstanding

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.

Zend Framework 2 - Set Template Path for Module

I googled alot and couldn't come up with an answer...
I'm using the tutorial-skeleton application. It automatically includes under 'view/album/album' the html files corresponding to my actions like add or index.
I'm using a submodule and the standard loading won't find my html-files. I followed this guide for setting a custom template path. This works for the index because here I use a ViewModel instance.
But my add/delete/edit actions just return an array like this one.
Is there a way to tell Zend that it should use a different directory to look for the views?
PS: I also tried this injectTemplate approach but no luck. It just sets the Controller namespace/path which is ok in my case.
This was an project specific issue...
I used MasterData as top namespace. When creating the directory tree in my module\MasterData\view I wrote masterdata instead of master-data. This caused the not finding of my views.
A dumb one... I know.

CodeIgniter module loading creates path clash with local classes?

Using CodeIgniter, from a controller (application/controllers/home.php), observe the line:
$this->load->library(array('account/authentication'))
AFAIK, this will:
Load 'authentication.php' from
application/modules/account/libraries/authentication.php
Load 'authentication.php' from application/libraries/account/authentication.php
So, what if both exist? Experimenting, it seemed like CI looks for the first one, and if no such exists, it loads the second one. Isn't that kind of weird behavior?? The two files might have nothing to do with each other.
Isn't there a way of unambiguously declaring if you are referring to a local file or to a module file?
AFAIK, there is no default directory application/modules and I can't find any reference for it in CI's docs and source.
I would say that CI's behavior is according to no.2
And indeed taking a closer look at CI's loader (system/core/Loader.php) reveals the following:
We start at function 'library'
Which calls function '_ci_load_class'
'_ci_load_class' disassembles the library name you passed into two parts: subdir and class name.
First it looks for the class in libraries/subdir/class. If it finds it - good, it loads it.
If the class was not found there, it looks for it in some other predefined pathes ($this->_ci_library_paths).
If the library is still not found, it makes a last attempt and looks for it in libraries/class/class.
The only thing I can think of, is that you have defined a custom library path which points to a modules directory. But even then, CI should look for the library in modules/libraries/account/authentication.php.
Edit:
I just noticed you tagged your question with hmvc, which does use a modules directory.
Unfortunately, I have no experience with it.
I would (obviously) assume this what causes the behavior you described.

PHP MVC 404/Error Handling for bad URLS

I am trying to build a custom MVC framework in PHP. I'm just starting out with this MVC and framework stuff and I'm not very good.
I created all the general stuff. The library for the model, controller and view and I got a general app up and running.
I would like to now incorporate some error handling. Primarily on the user side for bad urls. I want to make Page Not Found or 404 Errors. So i need a way to check for bad controllers,actions and query strings. And then send the users to a 404 page.
What is the best practice for doing this in an MVC environment?
EDIT
This is a learning based project it is not for production.
First of all it is not recommended to develop a custom framework your own if you are planning it for production. There are many great frameworks that you can make use of, with good flexibility and more importantly with more performance.
Coming to the problem. First write a custom exception handler for managing 404. I recommend to call them in your system/core class where you create Object of the controller and invoke the action, if they dont exists.
Add an error handler in your bootstrap.
For example, in mine I have:
public function error(){
$this->view->msg = 'Page not found';
$this->view->render('error/index');
}
Add a check for the method in the bootstrap. Where depends on your structure. If the method or controller isn't found call the error() method.
Thats probably the simplest way.
you can use .htaccess (if using apache) to route all request to your index page. Usually the the controller (and action), view is associated with a file or function. so, if you want to show custom error message, just check for the file, class, or its methods.
for example:- index.php?controller=control1&action=action1.
if(!file_exists('control1.php'))
if(!method_exists($controller, 'action1'))
//route to error handler
Well, if you are learning like you said, you shouldn't use your framework for production code because one thing is breaking the app at home and another one is loosing money with angry clients :)
Back to the problem. I've built my own custom framework for PHP applications and I have in my framework several Routers. The idea is that each Router handles a specific pattern of Route, like this:
http://someapplication.org/services/awebservice/
This code would call the ServiceRouter, which handles Routing web services. Before calling any Router I check if the Router exists, and if it does, then I would call a method to check if the route is valid, something like this:
if ( RoutingManager::RouterExists($route) )
{
$router = RoutingManager::GetRouter($route);
if ( !$router->IsValid )
RoutingManager::RedirectTo404();
}
The idea is to locate your 404 handler to a class, and delegate the task of routing into different classes to allow a variety of Routers and make your application more changeable (scalable)
Hope I can help!

Categories