How to control public resoucre(js, css, image,...) in Codeigniter like Express - php

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');

Related

How to change URLs in a Site developed using Laravel?

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.
}
}

Yeoman - php project

I'm starting a new php project and I'm trying to learn new techniques (for me). Grunt, yeoman etc.
Now I want to start a php project and found this example from Bradleycorn => generator-php. As far as I think, I have everything working, but I can't rund my development local site using grunt server. I'm getting a error:
Running "php:server" (php) task
Invalid address: http://localhost/myproject.nl:80
I have this folder structure:
\Applications\XAMPP\xamppfiles\htdocs\myproject.nl\
Beneath this folder:
myproject\
|--.sass-cache\
|--.tmp\
|--app\
|--dist\
|--node_modules\
|--bower.json
|--Grunftile.js
|--package.jason
|--router-dist.php
|--router.php
In the Gruntfile.js this code is placed (part of the code with the dev URL):
module.exports = function (grunt) {
// load all grunt tasks
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
// CONFIGURABLE PATHS
// The yeomanConfig object contains file paths and other "constants" that are used throughout
// The rest of this Gruntfile. Basically, any value that is used in multiple places should be
// put here for ease of maintenance. Update the value here, and all other places are updated
// automagically.
var yeomanConfig = {
app: 'app',
dist: 'dist',
siteURL: 'www.myproject.nl',
devURL: 'http://localhost/myproject.nl',
devPort: 80
};
I also tried this devURL http://localhost/myproject.nl/myproject/dist:, but also not working. What should the devURL be in this case?
PS: I also want to run a local database, I'm using XAMPP for that.

Template not found error - Fat Free Framework

I have worked through the examples in the documentation for the Fat Free Framework, and there is one example that I cannot get to work. It is the following:
$f3=require('lib/base.php');
$f3->route('GET /',
function($f3) {
$f3->set('name','world');
$template=new Template;
echo $template->render('template.htm');
// Above lines can be written as:
// echo Template::instance()->render('template.htm');
}
);
$f3->run();
I receive an error that the Template is not found. The error points to the line in which the template.htm file is being rendered and complains of Preview->render (i.e. its superclass, instead of Template->render). I don't even see a file for a Preview class in the codebase.
Interestingly, if I use the same file for the View example (below), it works just fine.
$f3=require('lib/base.php');
$f3->route('GET /',
function($f3) {
$f3->set('name','world');
$view=new View;
echo $view->render('template.htm');
// Previous two lines can be shortened to:
// echo View::instance()->render('template.htm');
}
);
$f3->run();
However, if I am going to use this framework, I would like to be able to utilize its templating feature as well.
Does anyone with experience with this framework have any idea what could be the problem? I downloaded the code from Github (https://github.com/bcosca/fatfree).
By default F3 uses the same folder where is located your main file (where you start the framework instance). You can change this behavior by setting a new path for the UI parameter. In short:
$f3 = \Base::instance();
$f3->set('UI', path_to_your_templates);
let's say you have the following structure:
- app
-- views
--- template.htm (your template)
- public
-- index.php (where your init the framework)
-- (template files are expected here by default)
public/index.php looks like:
$f3 = \Base::instance();
$f3->set('UI', __DIR__.'/../app/views/');
$f3->route('GET /',
function($f3) {
echo Template::instance()->render('template.htm');
}
Hope it helps.
Use .html instead of .htm. Yep, it really matters.
I have no experience using fat free framework, but a general pointer on how to debug this issue.
Apparently the file not found exception is being thrown by some code inside fat free framework. Try debugging that using XDebug
I ran across this issue with version Fat Free Framework 3.5.1
The issue appears since the framework OOB (in at least this version) is wired with a sample such that the templates are looked for in the 'ui/' subfolder of the root fat free framework folder.
What tells me that? Well... the OOB config.ini has the following contents:
[globals]
DEBUG=3
UI=ui/
To easily solve the problem either:
Put the file 'template.htm' in the 'ui/' subfolder
OR
Rename the 'ui/' subfolder to whatever you like in the config.ini and put the 'template.htm' file in that location
TIP: Make sure whatever UI path you specify ends in a / and if you need to specify multiple paths you can use the | or , or ; separators (making sure each path ends in a /)

Yii: Creating a Demo Site Without Replicating the Code Base

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/

Changing dependency paths when deploying to different directory structure than developing in

What are some popular ways (and their caveats) of handling dependency path changes in scripted languages that will need to occur when deploying to a different directory structure?
Let the build tool do a textual replace? (such as an Ant replace?)
Say for example the src path in a HTML tag would need to change, maybe also a AJAX path in a javascript file and an include in a PHP file.
Update
I've pretty much sorted out what I need.
The only problem left is the URL that gets posted to via AJAX. At the moment this URL is in a JS config file amongst many other parameters. It is however the only parameter that changes between development, QA and production.
Unfortunately dynamically generated URLs as #prodigitalson suggested aren't desirable here--I have to support multiple server side technologies and it would get messy.
At the moment I'm leaning towards putting the URL parameter into its own JS file, deploying a different version of it for each of development, QA and production, additionally concatenating to the main config file when deployed.
IMO if you need to do this then youe developed in the wrong way. All of this shoul dbe managed in configuration file(s). On th ephp side you should have some kin dof helper that ouputs the path based on the config value... for example:
<?php echo image_tag('myimage.jpg', array('alt'=>'My Image')); ?>
<?php echo echo javascript_include('myscript.js'); ?>
In both these cases the function would look up the path to the javascript and image directories based on deployment.
For links you should be bale to generate a link based on the local install of the application and a set of parameters like:
<?php echo link_to('/user/profile', array('user_id' => 7)); // output a tag ?>
<?php echo url('/user/profile', array('user_id'=>7)); // jsut get the url ?>
As far as javascript goes you shouldnt have any paths hardcoded in a js file that need to be changed. You should make your ajax or things that are path dependent accept parameters and then you send these parameters from the view where you have the ability to use the same scripted configuration.. so oyu might have something like:
<script type="text/javascript">
siteNamespace.callAjax(
'<?php echo url('/user/profile/like', array('user_id' => 7)); ?>',
{'other': 'option'}
);
</script>
This way you can change all this in a central location based on any number of variables. Most MVC frameworks are going to do something like this though the code will look a bit different and the configuration options will vary.
I would take a look at Zend Framework MVC - specifcally the Config, Router, and View Helpers, or Symfony 1.4 and its Config, Routing and Asset and Url Helpers for example implementations.

Categories