Referencing script files from MVC - model-view-controller

I am having problems referencing scripts that should be included in my view, when I access the page using a different route my scripts fail.
The idea is that two routes actually point to the same action:
http://localhost/PaydayWebsite/registration
http://localhost/PaydayWebsite/organizations/p001/departments/vest/employees/chn/registration
where the second just include more params for my action. I have tried using
ResolveUrl, Url.Content and mvccontribs Html.ScriptInclude but neither seem to work. Any ideas?

You should be able to use Url.Content, but you'll need to make your path relative to the root of the application rather than the current path.
Use
Url.Content( "~/Content/Scripts/jquery-1.3.2.min.js" )
rather than
Url.Content( "../../Content/Scripts/jquery-1.3.2.min.js" )

Related

Getting a route to an external laravel instance

I have two separate Laravel instances/sites running on a server and want to be able to generate a url to a named route on one from code within the other.
For example the following named route exists in the first instance:
Route::get('users/my_account', array('uses' => 'UsersController#myAccount', 'as' => 'my_account'))
In the second instance I want to generate a url to the route above. Can anyone think of a clean way to do this, without explicitly knowing the url (i.e. only knowing the name of the route 'my_account')?
Basically I want to expose the RouteCollection of one site to the other...
That's a pretty interesting question. There's no natively supported way of doing that and, from what I know, it won't ever.
You could try loading the routes file of the first application, parsing it's configurations (you will need that for reverse routing), construct a Router instance and use it, but I'm sure it won't be simple at all.
If you have a really, I mean really, good reason to use reverse routes, you can try building a small API on the first application. That API should receive the parameters necessary, those used in url($params), and return the full url (with domain and everything). Although, this will introduce some serious performance issues.
IMHO, stick to hard coded my_account, leave a comment on the first application route and/or controller explaining that it's used on another project and move on :)
I may call this a dirty trick. Supposing you have the following structure in your file system, where both paths are Laravel apps:
/path/to/apps/app1
/path/to/apps/app2
And you want to load the routes file from app1 into app2. You can do it as follow:
include "../app1/apps/routes.php";
$url = URL::route('register');
Voilà! But, although it worked for me there are some points to consider.
Include that file, will surely overwrites your current route collection for that process.
If that last is true, then you can have problem generating other URLs, maybe in your views.
The domain name will be of the current Laravel instance. It means that your URLs generated into app2 will hold the domain name of app1. I believe this is not what you want. But you can always generate non-absolute URLs with URL::route('register', null, false).

CakePhp2 defined CAKE_CORE_INCLUDE_PATH, now DS and CORE_PATH undefined in ShellDispatcher

In order to share CakePhp2 core between many sites I edited CAKE_CORE_INCLUDE_PATH in webroot/index.php to point to the cake directory. That works and I can reach my welcome page.
However, when I attempted to run the Cake Console, I ran into issues with ShellDispatcher.php not defining DS and CORE_PATH because they were only defined if CAKE_CORE_INCLUDE_PATH was NOT defined. Once I defined them out of the if statement which checks if CAKE_CORE_INCLUDE_PATH was not defined, I was good to go. However, I would prefer not to "hack" this file because I want to keep the cake core files clean. Are there any better and cleaner options?
I also had to defined CAKE_CORE_INCLUDE_PATH and use it to set $dispatcher in Console/cake.php which is part of the app of course.
Yes there are. As a start never define application-wide variables in Webroot/index.php. As a matter of fact you shouldn't be touching this file at all. You can define variables in
Config/bootstrap.php.
You were getting the error because when in a Shell you're not firing Webroot/index.php at all - you're actually running PHP's CLI and CakePHP fires off in a different manner.
It will go through the bootstrap.php file of course.
You should also use this file to define any global vars, but there is a little bottleneck
here when using PHP's $_SERVER variable's web server related members - e.g. HTTP_HOST and the definition: $myHost = $_SERVER['HTTP_HOST'];. If you start a shell Cake will try to set this variable and it will fail throwing an error. This is because as mentioned before PHP will be running in CLI mode when the CakeShell is envoked. There is a way to detect this of course - you can use $_SERVER['SCRIPT_FILENAME'] or $_SERVER['SCRIPT_NAME'] in bootstrap.php to identify if you're in CLI or not. :)

PHPUnit + CodeIgniter multiple objects with same name

I currently test my CodeIgniter app with phpunit by using CIUnit (https://bitbucket.org/kenjis/my-ciunit). The problem is that I have multiple controllers with the same name. I have a controller in the root controller directory named "Blog" and I have a controller called "Blog" in the controller/ajax/ directory.
The reason is to seperate all ajax requests from the main controller.
When I am running tests on both files, I get the following error:
PHP Fatal error: Cannot redeclare class Blog in ...
Well, I am not suprised I am getting this error.
What are my options to resolve this?
Prefix controllers in ajax directory with "ajax" (looks only a bit stupid url/ajax/ajax_blog)
Use namespaces (I guess I need to namespace codeigniter too then)
Create 3 seperate phpunit.xml files
This aren't really solutions I am looking for. Do I have any other options? Is it somehow possible to run each testsuite seperatly, but still in one command? Can I "clean" objects between testsuites? Anything else?
There are no other options except those you mentioned, as it is impossible to "unload" class definitions in PHP.
Naming two controllers the same is not a problem when you run CI normally, since only one controller is instantiated per request, but something that should be avoided.
If it is just the ajax-url you don't like, maybe override it in a route (in config/routes.php):
$routes['ajax/blog'] = 'ajax/ajax_blog';

How To Use Model Of Another Application in Codeigniter

I am working on a project where I create Two Application hosted in same site.
My structure is given below…
SITE
SYSTEM
APPLICATION
font_end
back_end
Now my question is,is it possible to access model of one application from another application.
As example, I have a model named ‘User_model’ in font_end application. Is it possible to use this model from back_end application.
Thanks.
Yes, it is possible, but there is a but. It doesn't matter where your files are in an absolute sense, but it is not necessarily the easiest thing in the world to accomplish.
Your best bet is to use symlinks if you can and link them into a sub-directory of your models directory. This would be simple and clean.
Barring that, you should extend Loader and overwrite the &model method to look in the secondary directory (perhaps reassign $path to the alternate application's model folder if $path == 'frontend').
If that also isn't an option, loading is done through APPPATH.'models/'.$path . '/' .$model.EXT. This means you can access the model by the relative path to APPPATH.'models/'. Don't do that if you can possibly avoid it, however. It is non-obvious and an invitation to errors.
I tried your last version (error prone I know) and got this result:
Unable to locate the model you have specified: ext.
I used this load code to access the frontend model from my backend:
$this->load->model('APPPATH.'/models/frontend/'Frontend_Model'.'EXT');
apppath and ext constants should be used like variables, but if I put it this way my notepad ++ highlighting goes wrong:
$this->load->model(APPPATH.'/models/hp/'Homepage_Model'.EXT)
admin/application/model/accounts_model.php
application/controller/home.php
Put this code in home.php to use model of admin applicaton
$this->load->model('../../../Unicorn/application/models/accounts_model');

file/page not found when uploaded online

I am working on a new module of existing live project. It is a website developed in PHP Zend Framework. New module is on admin side. It runs properly on my localhost/virtualhost.
When I uploaded it online with correct directory path it is found that one file is not found.
It is called like
www.example.com/admin/controllerName/actionName
All the actions works except one action that doesn't display anything and returns exception error mentioning that page or file not found.
What could be the issue? I have checked folders. If one action for the same controller works than why doesn't other. Both have their .phtml files in View section.
Help would be appreciated.
Would I be right if I guessed your local development environment was Windows?
It's probably a filename case sensitivity issue.
Assuming your request looks like
www.example.com/admin/fusionmaps/newpage
I'm not sure how you've setup your modules but if it's reasonably standard, you should have something like this (note the upper and lowercase characters)
application/modules/admin/controllers/FusionmapsController.php
The controller classname should be Admin_FusionmapsController with action public function newpageAction()
The view script should be at
application/modules/admin/views/scripts/fusionmaps/newpage.phtml

Resources