I have a website being developed using Laravel 4 by a freelance dev. While the developer has developed the site with some standard URL's for each page, I want to be able to change the words in URL to suite each of my target markets.
For example, developer made URL of one page: www.site.com/public/city/vehicles
Later, i want to be able to change to www.site.com/Rome/Cars or www.site.com/Sydney/bikes
However the developer says it wont be possible later on to change URLs as this is limitation in Laravel. Can anyone please shed some light on this and how to do this?
Why it is not possible ?? URL can me made dynamic if you want . Using route as
Route::get('/city/{slug}/{slug}',array('as'=>'city.vehciles','uses'=>'yourcontroller#yourmethod'));
This will output :
www.site.com/city/Rome/Cars
//if public folder is removed from url .
//Here `Rome` and `cars` are dynamic and the value comes as per the slug value from database.
In the above route slug are the thing that can me made dynamic . Just keep some place to add slug while adding vehicle in your dashboard from where you add vehicles.
Also, if you want to explore more then please see this doc .
Hope you get it .
You can remove "/public/" from your Laravel 4 website path by editing your Apache2 configuration files.
This file can be in different places (depending on your server setup), but it should be easily findable. E.g. for AWS EC2 (Ubuntu 14.04) it's /etc/apache2/sites-available/000-default.conf
You want to place this snippet within that configuration file:
DocumentRoot /var/www/YOUR_PATH/public
<Directory "/var/www/YOUR_PATH/public">
AllowOverride ALL
</Directory>
Remember to call service apache2 restart so your server recognizes and serves this update.
Also, depending on how your developer built your website, you might need to update your Laravel routing file too.
For reference it should look something like this (app/Http/routes.php):
Route::get('ajax/support/{city}/{vehicle}', 'MyController#MyMethod');
Then you'd have a matching method like so (app/Http/Controllers/MyController.php):
class MyController extends Controller
{
public function MyMethod(Request $request, $city, $vehicle)
{
// You can access $city and $vehicle here.
}
}
Related
I'm newbie in Codeigniter. Almost the whole time ago I use NodeJS. Can you show me how to control public resource in Codeigniter like Express? I want use /js/dev in development mode instead of /js.
example:
When first load web page with path: http://xxxx.com/js/default.js will get content from /js/dev/default.js instead of /js/default.js at development mode
Below is my code in Express for this idea.
if (process.env.NODE_ENV === 'development') {//path dev -> min to product
app.use('/js', express.static('client/js/dev'))
app.use('/css', express.static('client/css/dev'))
}
You can create any folder on your root directory. After that you can access those files with base_url(), be sure your base_url is correct, you can change it on 'application/config/config.php'
<?php
echo base_url('public/js/xyz.js');
echo base_url('uploads/img/15.jpg');
I am using Yii bbii forum module and it works fine. But now I want to add comments-module so every forum post could be seperately commented.
At the begining it might look:
I followed instruction what is here, but I can't make it work :(
And why I even need to include this file, if I want to add just comment?
When I added the same widget to user page (just for testing) - I got "This item cann't be commentable" and it's fine because probably I don't have correct configuration in main.php.
Difference between widget in user model view and forum view is data passed in it.
Here:
public function actionPostComment()
{
if(isset($_POST['Comment']) && Yii::app()->request->isAjaxRequest)
{
$comment = new Comment();
$comment->attributes = $_POST['Comment'];
var_dump($comment);
var_dump returned this when tried to submit comment in forum, and here in user view page.
And probably it is not even possible to combine these to modules? I'm really new in Yii.
Updated:
Basically what I have done is:
exstracted comment module (under protected->modules)
in main.php (under protected->config) added all cofiguration in modules array:
'comments'=>array(
//you may override default config for all connecting models
'defaultModelConfig' => array(
//only registered users can post comments
'registeredOnly' => false,
'useCaptcha' => false,
.......
and in view file _post.php added following:
<?php $this->widget('comments.widgets.ECommentsListWidget', array(
'model' => $data,
));
and var_dump($data) gives this (when this is called in controller where post is reseaved).
An error message was given here:
include(BbiiPost.php): failed to open stream: No such file or directory
You said that the Bbii was working with Yii and it broke when you tried to add comments.
The links to your var_dump files are broken, but I did try to read them ;)
It looks like the comments module is interfering with the POST path so that when the form submission comes in it is in a different path from the root which is confusing the YiiBase's autoloader.
You could try explicitly adding the path to BbiiPost.php to the autoloader's search path, or finding where the include("BbiiPost.php") line is and changing it to an absolute path.
Another possibility is that the forum page you are on has links to add comments but the page routing has not been taken from the route. So it might be that the POST link to the comments is actually at /forum/123/comment/add instead of just /comment/add. So when the form is submitted it is trying to the comments/add controller/action but finding that it is in /forum/view and getting confused about the paths to the include files.
I have generally found that the instructions on the Yii (v1) [v2 docs are much better] site for these modules is flaky at best. Quite often the source download link on the page points to an old buggy version of the code as the project has usually moved somewhere else. You generally need to have a pretty good PHP/Yii knowledge to debug these user-submitted modules and get them working.
Forgive me for my English
I am new in PHP. And I'm building a site using Silverstripe and trying to configure Vimeo-Service-module. I'd follow the steps from this link
https://github.com/r0nn1ef/Silverstripe-Vimeo-Service-module
I did everything that mentions in the article. And created a page in admin panel of VimeoGallery page type and set the parameters on Videos tab to grab the videos for display.
After created page, I visited my and clicked on video menu but then all I see is no videos returned. It is showing blank page and no any error messages.
Is that I've done anything wrong. Please guide me...
Thanks in advance.
OK, I think I see the issue here. You are calling VimeoService::setAPIKey() however accessing the method like that is deprecated in the new version (the 2.0 branch - I was incorrect in my comment when I mentioned master) of the module.
The module instead uses the Site Config in the CMS to set the API key and a few other settings.
Now just remove VimeoService::setAPIKey() from your _config.php file, run /dev/build and set the API key through the CMS.
EDIT
On line 142 of VimeoGalleryPage.php, there is a function called flushCache. Replace the code in that function with the following:
public function flushCache($persistent = true) {
parent::flushCache($persistent);
unset($this->_cachedVideos);
}
Basically, the code in the 2.0 branch for this function does not correctly extend the same named function in SiteTree.
I need to set up a demo site for users to try a web app before signing up. The demo would be based on production code, however, it would require minor code changes: connection to a demo database, automatic creation/login of a new guest account for each user, etc.
The obvious solution is to replicate my code base as a second demo website and edit as necessary. Keeping the demo code in sync with production code is easy enough by adding a branch in subversion. I'm less than thrilled, however, at the prospect of having to do two updates on my server (production and then demo) every time I push code from development to production.
Initially I thought I might be able to replicate the website through a module. It's unclear if this is possible, however.
Is there a mechanic in Yii to execute an altered version of a website (config file and selected controllers)?
Never do before, so just an idea
solution with few files in other dir
create a separate a demo dir and map it on your demo URL
In this dir put this index.php (may be your .htaccess too)
<?php
$yii=_PRODUCTION_PATH_.'/framework/yii.php';
$config_prod=_PRODUCTION_PATH_.'/protected/config/main.php';
$config_demo=dirname(__FILE__).'/demo_main.php';
require_once($yii);
$config = CMap::mergeArray($config_prod,$config_demo);
Yii::createWebApplication($config)->run();
the demo_main.php override the classes (user, db) to manage a better demo experience:
<?php
return array(
'basePath'=>_PRODUCTION_DIR_.DIRECTORY_SEPARATOR.'..',
'components'=>array(
'user' => array(
// here you override the user class with a DEMO only user
'class'=>'DemoUser',
)
),
solution with all files of prduction site in a different dir
Here follows the index.php in root dir
<?php
$yii='../framework/yii.php';
$configMain = include dirname(__FILE__).'/protected/config/main.php';
$configProd = include dirname(__FILE__).'/protected/config/production.php';
$configDemo = include dirname(__FILE__) . '/protected/config/demo.php';
require_once($yii);
// for the demo version
// instead of the comment can be an *if* or any solution to manage 2 configs
//$config = CMap::mergeArray($configMain,$configProd);
$config = CMap::mergeArray($configMain,$configDemo);
Yii::createWebApplication($config)->run();
demo.php is analogue to "demo_main.php" overridig classes and configs for the demo version of the site.
The testdrive demo app is configured for this - after you install, note the separate index-test.php, and protected/config/test.php.
Unlike #IvanButtinoni's suggestion, you'll need to access index-test.php, instead of index.php, so you may need to modify your .htaccess if you're using clean URLs to allow access to index-test.php.
When I do this, I usually write a custom init in the base controller.php:
public function init() {
// use test layout if using test config
if (isset(Yii::app()->params['test'])) {
$this->layout='//layouts/test';
}
parent::init();
}
Obviously, I have a test parameter in my test.php . . .
The only difference in my two layouts is that one sets the background color to be a bright yellow, just so it's very clear you're on a test site.
If I have understood well (according to the comment answers to original post) then There are several ways. Here is a link that I think can help great deal. It helped me set up and may be will help you!
In Yii 2 it will be inherently supported
http://www.yiiframework.com/wiki/33/
I'm setting up routes in application.ini, so when I try to access /moved, it displays cont/move. It works but only if I type moved all lower letters exactly like it's setup on the first line. How can I make Moved or moVed or any other letter combination also work? Do I need to do it in Bootstrap to get finer control and how?
routes.test.route = moved
routes.test.defaults.controller = cont
routes.test.defaults.action = move
This is not a wise approach.
URLs are case sensitive for a reason. You will get duplicate content penalty from search engines. Users will be confused too.
However, you may create controller plugin to achieve this:
public function preDispatch()
{
$this->getRequest()->setControllerName(
strtolower($this->getRequest()->getControllerName());
)->setDispatched(false);
}
I've searched Google for a few minutes, and this page (http://joshribakoff.com/?p=29) covers a nice patch. This patch overrides the request object, instead of the dispatcher or the router.