I'm quite new to both Zend and QUnit and I've got a bit stuck when it comes to setting up my QUnit tests to test my JavaScript.
I'm trying to test to some DOM manipulation and I understand that I have to put the html I'm testing against inside a #qunit-fixture div in my Qunit test file. However I've got a partial view helper used in my main Zend application (works fine in my view scripts) which I just want to echo out rather than having to rewrite the html used in the helper itself (to avoid duplication). The JavaScript I am attempting to test is used in the partial view helper hence wanting to use it.
Here's the folder structure for my application with just the important files and a few others remaining:
├── application
│ ├── Bootstrap.php
│ ├── configs
│ ├── controllers
│ ├── layouts
│ │ └── scripts
│ ├── models
│ ├── plugins
│ └── views
│ ├── helpers
│ └── scripts
│ ├── error
│ ├── index
│ └── partials
│ └── partialViewHelperIWantToUse.phtml
├── docs
├── features
├── Gemfile
├── Gemfile.lock
├── js-tests
│ ├── qunitTestFile.html
│ └── vendor
│ └── qunit
│ ├── qunit.css
│ └── qunit.js
├── library
│ ├── Custom
├── public
│ ├── css
│ ├── img
│ ├── index.php
│ └── js
│ ├── jquery
│ │ └── jquery-1.7.2.min.js
│ └── javaScriptIWantToTest.js
├── Rakefile
├── tasks
└── tests
├── application
│ ├── controllers
│ └── models
├── bootstrap.php
├── library
│ └── Custom
└── phpunit.xml
I want to do something like this in my qunitTestFile.html (found in js-tests)
<div id="qunit-fixture">
<?php echo $view->partial('partialViewHelperIWantToUse.phtml') ?>
</div>
but it currently doesn't work. Renaming the qunitTestFile to have a .phtml extension causes nothing to echo out but the error "call to a member function partial() on a non-object" appears in the apache error log (I expected that but it was a simple thing to try!). I have a hunch that I might need to create another bootstrap file or something but both and Zend and Qunit are new to me so I'm a bit lost. =)
I hope that's clear and I've given enough information but let me know if it isn't.
Thanks!
Since I do not exactly know which Zend version you use, I am not sure if this helps you:
The partial()-Function is a helper of your view. Since a View .phtml File is called in a Zend_View-Context (if you use an Controller-Action to show the View) you should use
$this->partial('...');
You can setup a Zend_View for yourself, but according your directory structure, I assume you use an MVC-Pattern.
Related
Im creating a very basic login page and i'm trying to use php to verify the user login. Here is the code I'm using to access the php file.
axios.post("login.php", {
user: 'Fred',
pass: 'Flintstone'
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
The PHP file is located within the src folder of the react app.
── src
│ ├── components
│ │ ├── BrowsePage
│ │ │ ├── BrowsePage.css
│ │ │ ├── BrowsePage.js
│ │ │ └── default.jpg
│ │ ├── CreatePage
│ │ │ ├── CreatePage.css
│ │ │ └── CreatePage.js
│ │ ├── Header
│ │ │ ├── Header.css
│ │ │ └── Header.js
│ │ ├── LoginPage
│ │ │ ├── LoginPage.css
│ │ │ ├── LoginPage.js
│ │ │ └── logo.svg
│ │ ├── ProfilePage
│ │ │ ├── ProfilePage.css
│ │ │ └── ProfilePage.js
│ │ └── RecPage
│ │ ├── default.jpg
│ │ ├── RecPage.css
│ │ └── RecPage.js
│ ├── index.css
│ ├── index.js
│ ├── login.php
│ └── registerServiceWorker.js
When I make the call it logs
xhr.js:178 POST http://localhost:3000/login.php 404 (Not Found)
The current path to the php document does not work, and none of the others I've tried work. What is the path to make an axios call to this php document?
You'll need to setup a server locally that your React application can proxy certain http requests to. This server will run your login.php script and authenticate the username/password. create-react-app looks for a proxy value in your package.json and tells webpack-dev-server to forward any calls to api/foobar to wherever you have declared that your back-end will be running.
In your package.json add:
"proxy": "http://localhost:8000"
This tells React to forward requests made to http://localhost:3000/api/login to http://localhost:8000/api/login
Then modify your axios call to look like this
axios.post("/api/login", ..., ...).then()
Next, you have to get your PHP server running on http://localhost:8000 and set up your server application to handle POST requests made to /api/login.
I'm not a PHP guy but I've heard Laravel is nice to work with. It would be easier if your PHP backend was in its own directory completely.
I have just got Slim PHP Framework with composer. Can anyone suggest me how to use Controller and Model in slim framework. And Where to put controllers and model in slim framework.Actually I want to use slim framework only for API. And I want to use controller for it. I have read its document but I am not able to find regarding controller and models.
Slim doesn't enforce any particular layout for your application.
I tend to like to separate out PHP source from HTML templates, so I use this pattern (taken from slim-bookshelf):
app/
├── src
│ ├── Bookshelf
│ │ ├── Author.php
│ │ ├── AuthorController.php
│ │ ├── Book.php
│ │ ├── BookController.php
│ │ └── TwigExtension.php
│ ├── dependencies.php
│ ├── middleware.php
│ └── routes.php
├── templates
│ ├── bookshelf
│ │ ├── author
│ │ │ ├── books.twig
│ │ │ ├── edit.twig
│ │ │ └── list.twig
│ │ └── book
│ │ └── list.twig
│ └── layout.twig
└── settings.php
However, my APIs do not have templates, so I move everything up a level. This example comes from slim-bookshelf-api and uses a separate class for each route's action rather than a controller class:
src
├── App
│ └── Action
│ ├── HomeAction.php
│ └── PingAction.php
├── Bookshelf
│ ├── Action
│ │ ├── CreateAuthorAction.php
│ │ ├── DeleteAuthorAction.php
│ │ ├── EditAuthorAction.php
│ │ ├── GetAuthorAction.php
│ │ └── ListAuthorsAction.php
│ ├── Author.php
│ ├── AuthorMapper.php
│ └── AuthorTransformer.php
├── dependencies.php
├── middleware.php
├── routes.php
└── settings.php
New to CI, so it's probably safe to assume misunderstandings...
My folder structure looks like
.
└── www
├── appthing
│ └── V5
│ ├── application
│ │ ├── config
│ │ ├── controllers
│ │ │ ├── api
│ │ │ └── V1
│ │ │ ├── settings.php
│ │ ├── ...
│ │ └── views
│ └── system
└── vhosts
└── appthing
index.php
.htaccess
htaccess
My apache config in /etc/apache2/sites-available/000-default.conf looks like:
DocumentRoot /var/www/www/vhosts/appthing
<Directory "/var/www/www/vhosts/appthing">
AllowOverride All
</Directory>
When I navigate to ipaddress/index.php I get an authentication error, which is good, since I can at least access the index.php file. However, if I try to go to index.php/settings I get a CI 404 error. The same code works on my computer (OS X, trying to put it on a AWS Ubuntu 16 instance currently), so it's not a problem with CI semantics.
I think you need to set your Documentroot to /var/www/www/appthing/V5. Normally you should have and index.php file in your CI project which will redirect you to a home (standard = welcome.php) controller.
I have created a little Zend Framework 2 module called CMS to write simple articles in my site. This module follow uses Zend Db and the TableGateway class in order to get the data from the database.
I have read many website and books about the strategies to create a module and I prefer the short and fast way using these file structure:
.
├── Module.php
├── config
│ └── module.config.php
├── data
│ └── data.sql
├── src
│ └── Cms
│ ├── Controller
│ │ ├── IndexController.php
│ │ ├── PageAdminController.php
│ │ └── PageCategoryAdminController.php
│ ├── Form
│ │ ├── Element
│ │ │ ├── PageCategories.php
│ │ │ └── ParentPages.php
│ │ ├── PageCategoryFilter.php
│ │ ├── PageCategoryForm.php
│ │ ├── PageFilter.php
│ │ └── PageForm.php
│ ├── Hydrator
│ │ └── Strategy
│ │ └── DateTimeStrategy.php
│ ├── Model
│ │ ├── Page.php
│ │ ├── PageCategory.php
│ │ ├── PageCategoryTable.php
│ │ ├── PageTable.php
│ │ └── UrlRewrites.php
│ └── View
│ └── Helper
│ ├── Extract.php
│ └── Tags.php
└── view
└── cms
├── index
│ ├── index.phtml
│ ├── notfound.phtml
│ └── page.phtml
├── page-admin
│ ├── edit.phtml
│ └── index.phtml
├── page-category-admin
│ ├── edit.phtml
│ └── index.phtml
└── partial
└── tags.phtml
TableGateway Method
This file structure allows me to declare, for instance, the Page and PageTable class in the module.php and call the ServiceLocator to read and write the records from the database in this way:
$pageTable = $this->getServiceLocator()->get('PageTable');
In this case I can use this class to write the CRUD methods in the PageTable Class.
Inject Service Method
Then I have seen that there is a Service way to do the same thing where the CRUD actions are located in a Service Class that calls the TableGateway Class and inject by a Factory Class the Service into the __construct method of the Controller.
Service > TableGateway > Factory > Controller
Why have I to choose the Service strategy instead of the simple TableGateway?
Well your logic is a little off, the way is actually only
Controller calls Service calls TableGateway
The Factory is just a pattern to properly inject the dependencies.
Why use the Service
To abstract the behavior. The Service generally speaking is the instrument for your controllers to get the data. The Service then interacts with a data-source. What the data-source is, your controller doesn't care - hell not even your service should care. The service should only care for an implementation of an interface. This way, whenever you feel that you don't like TableGateway anymore but you wanna go Doctrine2, you don't have to change your Service. You don't have to change you Controller. All you have to change is the dependency of your Service. Instead of injecting a TableGateway class you inject your Doctrine2 class which matches the interface of the data-provider-dependency.
I come from a Codeigniter background. At the moment I am building a CMS in Laravel.
What I would like to know is how can I separate the backend and frontend in Laravel?
In Codeigniter i use to make two controller Admin_Controller and Front_Controller.
Article extends Admin_Controller
Article extends Front_Controller
and the file structure looked like this
controller
--admin
---user
---blog
---news
--user
--blog
--news
for admin controller I make separate folder and front end controller remain in root of controller folder.
Should I use the same logic in Laravel or is there a better way to do it?
If you want to create thinks like Taylor Otwell and 'the core' is trying to teach people do things in Laravel, this is a good start:
Your files could be organized as
├── app
│ ├── ZIP
│ │ ├── Controllers
│ │ │ ├── Admin
│ │ │ │ ├── Base.php <--- your base controller
│ │ │ │ ├── User.php
│ │ │ │ ├── Blog.php
│ │ │ │ ├── News.php
│ │ │ ├── Front
│ │ │ │ ├── Base.php <--- your base controller
│ │ │ │ ├── User.php
│ │ │ │ ├── Blog.php
│ │ │ │ ├── News.php
Configure a PSR-0 or PSR-4 (better) to autoload your classes:
"psr-0": {
"ZIP": "app/"
},
Create namespaces to all tour classes, according to your source tree:
<?php namespace ZIP\Controllers\Admin
class User extends Base {
}
<?php namespace ZIP\Controllers\Front
class Blog extends Base {
}
And create your base controllers
<?php namespace ZIP\Controllers\Admin
use Controller;
class Base extends Controller {
}
You can certainly do it the two controllers way or if you like even more separation (and a more 'laravel' way), write your front end and backend as separate packages (previously called bundles in Laravel 3).
They basically behave like standalone applications within your main app. They can have their own routes, models, controllers etc. You can also write 'core code' at the main application level which can be shared across the packages.
If you are moving to Laravel as you want to learn a new framework, then you should definitely try and get a handle on packages - very powerful.
If you are being 'made' to move to Laravel, or have some time pressure, just do it as you have normally done. Laravel is flexible and will be fine either way you do it.
For more info, see the docs.
Laravel current version (4 at time of writing) - http://laravel.com/docs/packages
Laravel 3 - http://three.laravel.com/docs/bundles