GithubHelp home page GithubHelp logo

2amigos / yiinitializr Goto Github PK

View Code? Open in Web Editor NEW
44.0 16.0 17.0 140 KB

Library that will help boost your application installation with ease and also to run Yii applications from its bootstrap files on a much cleaner way that the framework currently proposes.

License: Other

PHP 100.00%

yiinitializr's Introduction

IMPORTANT

DEPRECATED. At 2amigos we are not longer supporting Yii 1. We highly recommend you to adopt Yii 2 as soon as possible.

Yiinitializr

Library that will help boost your application installation with ease and also to run Yii applications from its bootstrap files on a much cleaner way that the framework currently proposes. For example:


// if installed via composer
require('./../../common/lib/vendor/autoload.php');

Yiinitializr\Helpers\Initializer::create('./../', 'frontend', array(
	__DIR__ .'/../../common/config/main.php',
	__DIR__ .'/../../common/config/env.php',
	__DIR__ .'/../../common/config/local.php'
))->run();

##How to use it If you are going to use Yiinitializr to make use of Yiinitializr\Helpers\Initializr you can easily install it via composer, but if you are going to use it within your application structure in order to configure your application according to your custom needs, then the recommended use is that you download its source files and place them on a top level folder.

###Configuration Settings As with Yii, you need to go through a bit of configuration settings if you wish to handle your project structure setup with composer. Don't worry, is not going to be too hard, the following is an example configuration file:

\\ where am i?
$dirname = dirname(__FILE__);
\\ where is the application folder?
$app = $dirname . '/../../..';
\\ where is the root?
$root = $app . '/..';

return array(
    // yii configurations
	'yii' => array(
		// where is the path of the yii framework?
		// On this example we have installed yii with composer
		// and as it is used after composer installation, we 
		// can safely point to the vendor folder.
		'path' => $app . '/lib/vendor/yiisoft/yii/framework'
	),
	// yiinitializr specific settings
	'yiinitializr' => array(
	    // config folders
		'config' => array(
		    // we just need the console settings
		    // On this example, and due that I used environments
		    // i created a custom console.php app for 
		    // Yiinitializr\Composer\Callbak class (see below example)
			'console' => $dirname . '/console.php'
		),
		// application structure settings
		'app' => array(
			// where is the root?
			'root' => $root,
			// directories setup
			'directories' => array(
				// where are the different configuration files settings?
				'config' => array(
					// 'key' is the configuration name (see above init example)
					'main' => $app . '/config',
					'console' => $app . '/config',
					'test' => $app . '/config'
				),
				// where are my runtime folders?
				'runtime' => array(
					// heads up! only the folder location as "/config" will be 
					// appended
					$app
				),
				'assets' => array(
					// where to write the "assets folders"?
					$root . '/www'
				)
			),
			'files' => array(
				// files to merge the main configuration file with
				// initializr will merge it automatically
				'config' => array(
					'main' => array('env', 'local'),
					'console' => array('env', 'local'),
				)
			)		
		),
	)
);

Here is an example of a custom console.php settings file when working with environments. As you saw on the previous code, this file on the example was located on the same Yiinitializr\config folder:

require_once dirname(__FILE__) . '/../Helpers/Initializer.php';
require_once dirname(__FILE__) . '/../Helpers/ArrayX.php';

return Yiinitializr\Helpers\ArrayX::merge(
	Yiinitializr\Helpers\Initializer::config('console', array('common', 'env', 'local')),
	array(
		'params' => array(
			// here is where the composer magic start.
			// Thanks! mr Tobias a.k.a Phundament man!
			'composer.callbacks' => array(
				'post-update' => array('yiic', 'migrate'),
				'post-install' => array('yiic', 'migrate'),
			)
		),
	)
);

####Examples

###Requirements It works in conjunction with composer to install the boilerplate but The minimum requirements by Yiinitializr that you have installed composer or have a composer.phar on your application root in order to run and ** PHP 5.3+**

###Resources

2amigOS!
web development has never been so fun
www.2amigos.us

yiinitializr's People

Contributors

borales avatar matperez avatar padavvan avatar tonydspaniard avatar vasiliy-pdk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yiinitializr's Issues

using CJSON

in EApiController json_encode is used to implement encoding array to json format but because this is a yii framework boilerplate why you are not using CJSON can handle model object as simple as array?

[Q] one image folder for frontend and backend

I start to deploy an app based on Yiinatializr-intermediate and it's been working fine but I've come across this issue.
Backend users will add articles and upload images. I created folder upload in site

directory do I have
upload
frontend
common
backend

I'm able to upload pictures to upload folder from backend app but I can't display it in frontend

<?php echo CHtml::image(Yii::app()->basePath . '/../upload/images/medium/' . $sport[0]->primaryPicture, ''); ?>

return no image
in Firebug console I get

"NetworkError: 404 Not Found - http://adrenalina.vhost/home/webadmin/www/html/adrenalina/upload/images/medium/2745-5011639458_374e174cdd_o.jpg"

The image is of course there

<?php echo Yii::app()->basePath; ?>

return my basePath

/home/webadmin/www/html/adrenalina/frontend 

Hope this could help you help me :)

Yiinitializr 2.0

Due to the success of Yiinitializr in the community, we are planning to make some changes on the Yiinitialzr site:

  • configuration enhancement
  • new templates
  • Yii1+, Yii2+ support
  • etc

Please, use this section to shoot ideas, improvements... any help would be highly appreciated!

Console and SAPI name

Just wanted to point out that Yiinitializr doesn't handle non 'cli' console connections very well.
There are a couple of places in the code that check for the existence of 'cli' as the Server API (I'm also including the Yiinitializr-advanced EActiveRecord in that count too)
e.g....

if (php_sapi_name() !== 'cli')

But I had problems when creating a cron job on my own server because the php_sapi_name() is actually 'cgi-fcgi' when run as a cron job (I believe there are other possibilities too).

Looks like they might have had a similar issue in the Yii core - CConsoleApplication Line 78

if(!isset($_SERVER['argv'])) // || strncasecmp(php_sapi_name(),'cli',3))
            die('This script must be run from the command line.');

Note: the php_sapi_name() part was commented out.

It would be useful if Yiinitializr can be modified in a similar way to allow the use of other SAPI names in the console.

Thanks,
Steve

autoload.php requiring problem

Hi,
First of all, I'm using advanced yiinitializr, not sure if it's the right place to ask or should've asked it in advanced initializr repo, sorry if I'm wrong.
I have a weird problem using yiic tool, which is php not finding autoload.php file.

Fatal error: require(): Failed opening required './../../common/lib/vendor/autoload.php' (include_path='.:') in /Applications/MAMP/htdocs/malek/yiic.php on line 13

my developing environment is OS X 10.8.4 using MAMP(PHP5.3.14), I tried other versions of PHP but nothing has changed.
the problem can be solved by changing this line:

require('./../../common/lib/vendor/autoload.php');

to this:

require(dirname(__FILE__).'/common/lib/vendor/autoload.php');

but why is that? index.php files are using the same way of addressing for autoload.php and they work fine, why is it not working within terminal and yii tool?

rename root breaks ALL paths

Problem : change the name of the root folder that contains all app folders (ie api, backend, common, etc) breaks paths to at least frontend and backend www.

This can be shown by dl an intermediate or advanced Yiinitializer template

  • cd into the folder & run the composer install
    • cd test-adv
    • php composer.phar install
  • accept the defaults
  • remove the backend htaccess and check the page loads ok
  • rename the root folder
    • cd ..
    • mv test-adv test2-adv2
    • cd test2-adv2
  • run composer install again to make sure paths are corrected
    • php composer.phar install
  • again accept the defaults
  • check the backend index page
  • shows some error similar to

Fatal error: Uncaught exception 'Exception' with message 'Unable to find 'yiinitializr.app.directories.config.'backend on the settings.' in /www/adv-test/common/lib/Yiinitializr/Helpers/Initializer.php:67 Stack trace: #0 /www/adv-test/common/lib/Yiinitializr/Helpers/Initializer.php(39): Yiinitializr\Helpers\Initializer::config('backend', Array) #1 /Users/kez/www/adv-test/backend/www/index.php(19): Yiinitializr\Helpers\Initializer::create('./../', 'backend', Array) #2 {main} thrown in /www/adv2-test2/common/lib/Yiinitializr/Helpers/Initializer.php on line 67

I have found no way around this short of using the downloaded template and copying all the configs modules and extensions in by hand.

This is a serious show stopper for testing purposes.
If there are specific logs required I can add them but this has me stumped.
its like the previous root folder name has been cached somehow and is not being regenerated on a per request basis.
Even If I remove all env.php, env.lock files and the common/lib/vendor folder and redo the composer install it makes no difference.

One thing to note is that if you remove the common/lib/vendor folder and rename the root back to what it was originally (in this case test-adv) and re-run the composer install the apps are fully up and running again.

I hope this is enough info to track this down because I really like the simpler Yiinitializr way vs the yii-boiler plate but this issue is really annoying.

need help in setting up an app

HI i am new to Yii. i need little help how to setup the professional template in yiinitializr

can you please provide some example in step by step guide @creocoder @tonydspaniard

thanks alot i want to make a high end application so need help in it

Shared hosting

Add ability or wiki info how to use/modify advanced yiinitializr templates on shared hostings with one www root. It can be like this:

/frontend/...
/backend/...
/www/
    index.php
    backend/
        index.php

Cronjob

Hi,
Thx for this usefull Tool. All works in application. Iam usin a basic app and now i need to implement a cronjob. Anyone can plz show me a standard example for this ?

i build a command.php like the same index.php

example :
https://gist.github.com/brewing/71a0ff513cac3e0dad6c

error :
Fatal error: Class 'Yiinitializr\Helpers\Exception' not found in /Users/brewing/webserver/facebook/app/lib/Yiinitializr/Helpers/Initializer.php on line 37

console.php my config file

https://gist.github.com/brewing/7a4050b38bdae1e6cffd

Sorry what i'am doing wrong ? i dismissed something ?
It would nice you can answer quickly because i need it fast.

Thx

Custom application class

In current implementation i can not create my own application with for example class ApiApplication because of application creation is hardcoded as web/console, i suggest to check the second param of Initializer::create(), and if it is an array then first element of it must be application class, and second one is config.
Small changes are also needed here:
https://github.com/2amigos/yiinitializr/blob/master/Helpers/Initializer.php#L41

So, overall the end version can be like this in index.php:

$config = array(
    'ApiApplication',
    'frontend'
);
Yiinitializr\Helpers\Initializer::create('./../', $config, array(
    __DIR__ .'/../../common/config/main.php',
    __DIR__ .'/../../common/config/env.php',
    __DIR__ .'/../../common/config/local.php'
))->run();

Configuration questions

Hi, few questions.

Is there something to do before production?
How to change env config from dev to prod?
How correctly add custom env config, like "staging"?

Thanks!

Composer update

I got error message while "php composer.phar install"

Problem 1

  • 2amigos/yiiwheels 1.0.1 requires 2amigos/yiistrap 1.0.0 -> satisfiable by 2amigos/yiistrap[1.0.0].
  • 2amigos/yiiwheels 1.0.1 requires 2amigos/yiistrap 1.0.0 -> satisfiable by 2amigos/yiistrap[1.0.0].
  • Can only install one of: 2amigos/yiistrap[dev-master, 1.0.0].
  • Installation request for 2amigos/yiistrap dev-master -> satisfiable by 2amigos/yiistrap[dev-master].

How can I fix this?

  • Installation request for 2amigos/yiiwheels 1.0.1 -> satisfiable by 2amigos/yiiwheels[1.0.1].

Gii generator is broken

I've tried to use Gii and got an errors. So I've wrote a tiny step-by-step instruction how to fix generated content. Thats not a complete fix, but could be helpfull for a start.

I think Gii should be extended to make it automatically.

For example i've generated Model YiiLog & CRUD for it.


I've recieved an error:

include(Controller.php): failed to open stream: No such file or directory

In our generated controller class we need to change:

class YiiLogController extends Controller

to:

class YiiLogController extends EController

Then I've recieved an error:

Declaration of YiiLogController::loadModel() should be compatible with EController::loadModel($class, $id, $criteria = Array, $exceptionOnNull = true)

In our generated controller class we need to remove loadModel & performAjaxValidation functions, because they are implemented in EController already.


After that we need to rewrite each call of loadModel function in our controller.

Find every:

$this->loadModel($id)

Change to:

$this->loadModel('YiiLog',$id)

Then I've recieved and error:

Property "YiiLogController.menu" is not defined.

Change ./common/extensions/components/EController.php file.
find:

public $breadcrumbs;

add below:

public $menu;

Add "flat" template

Hi, @tonydspaniard.
After yii-meetup, some developers wanted to use Yiinitializr on a shared hosting, but some hosting providers allow to use only 1 public_html folder.
So, my request is to create "super-flat" structure (like yii does with the default folder structure). Possible structure could be like this:

/www
- /app/
--- /controllers/
--- /models/
--- /lib/
--- /...etc /
- /assets/
- /themes/
- /index.php

Tests integrated in Yiinitializr

Hi! Thanks for your project.

I'm currently using advanced template, but have one big problem - tests. My application has been moved from standard Yii structure. Everything is ok, except tests. Are there any simple and nice way to integrate them? i mean configs, etc.

DEBUG constants doesn't work

    // yii config
defined('YII_DEBUG') or define('YII_DEBUG', isset($params['yii.debug']) ? $params['yii.debug'] : false);
defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL', isset($params['yii.traceLevel']) ? $params['yii.traceLevel'] : 0);
defined('YII_ENABLE_ERROR_HANDLER') or define('YII_ENABLE_ERROR_HANDLER', isset($params['yii.handleErrors']) ? $params['yii.handleErrors'] : true);
defined('YII_ENABLE_EXCEPTION_HANDLER') or define('YII_ENABLE_EXCEPTION_HANDLER', YII_ENABLE_ERROR_HANDLER);

This block of code doesn't work. For example if we take 'yiinitializr-intermediate' back-end index.php file, that code of block is processed after Yii framework is included, but the line require('./../../common/lib/vendor/yiisoft/yii/framework/yii.php'); which includes Yii framework sets debug constants if they are not already set. This leads to using default debug constants and not the ones set from configuration.

Further suggestions for configureability

"Moved" from Yii extension

Could you consider adding:

Url/Server dependent configuration;
Debug configuration based on Url option?
I currently do stuff like this in my 'index.php':

// Determine debug mode depending on site name or get parameter (secret_dbg_key in this example):

$prodtest=(preg_match('/^expressiontocomparewith?$/',getenv('HTTP_HOST'))>0);

$debugmode=!$prodtest&&(preg_match('/^localhost([:\/].*)?
$/',getenv('HTTP_HOST'))>0)||isset($_GET['secret_dbg_key']);

$isProduction = $prodtest||(preg_match('/^([^\/].*)?prodsite.com/',getenv('HTTP_HOST'))>0);
if($debugmode) {
    defined('YII_DEBUG') or define('YII_DEBUG',true);
    defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',5);
}

and similar for the configuration where I have

if(!CliCheck::isCli()) {
    // Could be: $host = $_SERVER['HTTP_HOST'];
    // I used in my setup:
    $host = getenv('SERVER_NAME');
} else {
    $host=gethostname();
}
/** Check if there is a site configuration */
$siteconf = dirname(__FILE__).DIRECTORY_SEPARATOR.$host.'_common.php';
if(file_exists($siteconf)) {
    $siteconf=require($siteconf);
} else {
    $siteconf=array();
}

which loads a configuration file based on the host name. "CliCheck::isCli()" checks if it is run from the command line or not. '$siteconf' gets merged with the default/common configuration.

other config file (backend env local or frontend env local and etc) does not include

so config method in initializer should be change:

public static function config($configName = 'main', $mergeWith = null)
{
    $files = array($configName);
    $directory = Config::value('yiinitializr.app.directories.config.' . $configName);
    if (null === $directory)
        throw new \Exception("Unable to find 'yiinitializr.app.directories.config.'{$configName} on the settings.");

    if (null !== $mergeWith)
    {
        if (is_array($mergeWith))
        {
            foreach($mergeWith as $file)
                $files[] = $file;
        }
        else
            $files[] = $mergeWith;
    }

    // do we have any other configuration files to merge with?
    $mergedSettingFiles = Config::value('yiinitializr.app.files.config.' . $configName);
    if (null !== $mergedSettingFiles)
    {
        foreach($mergedSettingFiles as $file)
            $files[] = $file;
    }

    $config = self::build($directory, $files);

    $params = isset($config['params'])
        ? $config['params']
        : array();

    self::setOptions($params);

    return $config;
}

I'm going to use Yiinitializr in an entrprise project hope to less bug :)

Is there a way to change settings.php to other location?

When config a new application using yiinitializr we have to edit settings.php but if we set up yiinitializr using composer. It may not be a good idea to change settings.php directly because if we update the package via composer again, our setting may be gone.

I look at the template using yiinitializr (those provide in the yiinitializr's main website). They take yiinitializr out side the composer's vendor directly. So I don't think it is possible in this version we have to do like those templates did.

But it could be cool if we can in the future. So we can maintain yiinitializr using composer while keep our settings.php the same.

Cool library by the way.

Some guidance with nginx

Hi Antonio, could you guide me how to config nginx using this skeleton?. It's making me crazy. Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.