本文整理汇总了PHP中yii\helpers\StringHelper::dirname方法的典型用法代码示例。如果您正苦于以下问题:PHP StringHelper::dirname方法的具体用法?PHP StringHelper::dirname怎么用?PHP StringHelper::dirname使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\helpers\StringHelper
的用法示例。
在下文中一共展示了StringHelper::dirname方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getThumbnailTrue
public function getThumbnailTrue()
{
if ($this->image) {
$name = \yii\helpers\StringHelper::basename($this->image);
$dir = \yii\helpers\StringHelper::dirname($this->image);
return Yii::getAlias($dir . '/thumb/' . $name);
}
}
示例2: actionIndex
public function actionIndex()
{
// --------------------------- TITLE -----------------------------------
$this->getView()->title .= ' :: ' . S::upperCamelize($this->action->id);
// TODO
// debug info ----------------------------------------------------------
AppDebug::dump(['method' => __METHOD__, 'line' => __LINE__, 'module' => $this->module->id, 'controller' => $this->id, 'action' => $this->action->id, 'dirname' => StringHelper::dirname(Yii::getAlias('@frontend')), 'version' => Yii::getVersion(), 'clientIp' => $this->getClientIp(), 'userIp' => $this->getRequest()->userIP, 'language' => Yii::$app->language, 'user' => Yii::$app->getUser(), 'isGuest' => Yii::$app->getUser()->isGuest, 'view params' => $this->getView()->params]);
// ---------------------------------------------------------------------
return $this->render('index');
}
示例3: loadSavedForms
/**
* walk througt all modules gii directories and collect Giant crud generator saved forms.
*
* @return array
*/
public static function loadSavedForms($generatorName)
{
$suffix = str_replace(' ', '', $generatorName);
if (self::$savedFormList) {
return self::$savedFormList;
}
/*
* get all possible gii directories with out validation on existing
*/
$giiDirs = [];
$giiDirs[] = \Yii::getAlias('@app/gii');
if ($commonGiiDir = \Yii::getAlias('@common/gii', false)) {
$giiDirs[] = $commonGiiDir;
}
foreach (\Yii::$app->modules as $moduleId => $module) {
/*
* get module base path
*/
if (method_exists($module, 'getBasePath')) {
$basePath = $module->getBasePath();
} else {
$reflector = new \ReflectionClass($module['class']);
$basePath = StringHelper::dirname($reflector->getFileName());
}
$basePath .= '/gii';
$giiDirs[] = $basePath;
}
/*
* from all gii directories collec forms
*/
$forms = [];
foreach ($giiDirs as $basePath) {
/*
* search in module gii directory all forms json files
* with required suffix
*/
if (!file_exists($basePath)) {
continue;
}
$files = scandir($basePath);
foreach ($files as $file) {
if (!preg_match('#' . $suffix . '\\.json$#', $file)) {
continue;
}
$name = preg_replace('#' . $suffix . '\\.json$#', '', $file);
$forms[$moduleId . $name] = ['jsonData' => file_get_contents($basePath . '/' . $file), 'label' => $moduleId . ' - ' . $name];
}
}
return self::$savedFormList = $forms;
}
示例4: setDomains
/**
*
* @param string $url
* @return self
*/
protected static function setDomains($url)
{
self::$baseFolder = '';
if (empty(self::$homeUrl)) {
self::$homeUrl = rtrim(StringHelper::dirname($_SERVER['PHP_SELF']), '/');
}
if (empty(self::$baseFolder)) {
if ($str = mb_stristr(self::$homeUrl, 'admin', TRUE)) {
self::$baseFolder = $str . "admin";
}
if ($str == false && !empty(self::$homeUrl)) {
self::$baseFolder = rtrim(self::$homeUrl, '/');
}
self::$baseFolder = rtrim(self::$baseFolder, '/');
}
$url = StringHelper::byteSubstr($url, StringHelper::byteLength(self::$baseFolder), StringHelper::byteLength($url));
self::$domains = explode('/', ltrim($url, '/'));
return self::$domains;
}
示例5: getThumbnailTrue
public function getThumbnailTrue()
{
$image = $this->avatar;
$pos = strpos($image, "http");
if ($pos !== FALSE) {
return $this->avatar;
} else {
if ($image) {
$name = \yii\helpers\StringHelper::basename($image);
$dir = \yii\helpers\StringHelper::dirname($image);
return Yii::getAlias($dir . '/thumb/' . $name);
} else {
return Yii::$app->request->baseUrl . '/img/photo.jpg.png';
}
}
}
示例6: ltrim
$searchModelAlias = $searchModelClass . 'Search';
}
/* @var $class ActiveRecordInterface */
$class = $generator->modelClass;
$pks = $class::primaryKey();
$urlParams = $generator->generateUrlParams();
$actionParams = $generator->generateActionParams();
$actionParamComments = $generator->generateActionParamComments();
$temporal=new $class();
echo "<?php\n";
?>
namespace <?= StringHelper::dirname(ltrim($generator->controllerClass, '\\')) ?>;
use Yii;
use <?= ltrim($generator->modelClass, '\\') ?>;
<?php if (!empty($generator->searchModelClass)): ?>
use <?= ltrim($generator->searchModelClass, '\\') . (isset($searchModelAlias) ? " as $searchModelAlias" : "") ?>;
<?php else: ?>
use yii\data\ActiveDataProvider;
<?php endif; ?>
use <?= ltrim($generator->baseControllerClass, '\\') ?>;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
<?php if ( is_a($temporal, 'app\models\TramitExt') ): ?>
use app\models\USUARIOS;
use app\models\PasosTramite;
示例7: ltrim
$searchModelClass = StringHelper::basename($generator->searchModelClass);
if ($modelClass === $searchModelClass) {
$searchModelAlias = $searchModelClass . 'Search';
}
/* @var $class ActiveRecordInterface */
$class = $generator->modelClass;
$pks = $class::primaryKey();
$urlParams = $generator->generateUrlParams();
$actionParams = $generator->generateActionParams();
$actionParamComments = $generator->generateActionParamComments();
$tableSchema = $generator->getTableSchema();
echo "<?php\n";
?>
namespace <?php
echo StringHelper::dirname(ltrim($generator->controllerClass, '\\'));
?>
;
use Yii;
use pavlinter\adm\Adm;
use <?php
echo ltrim($generator->modelClass, '\\');
?>
;
<?php
if (!empty($generator->searchModelClass)) {
?>
use <?php
echo ltrim($generator->searchModelClass, '\\') . (isset($searchModelAlias) ? " as {$searchModelAlias}" : "");
?>
示例8: ltrim
$modelClass = StringHelper::basename($generator->modelClass);
$searchModelClass = StringHelper::basename($generator->searchModelClass);
if ($modelClass === $searchModelClass) {
$searchModelAlias = $searchModelClass . 'Search';
}
/* @var $class ActiveRecordInterface */
$class = $generator->modelClass;
$pks = $class::primaryKey();
$urlParams = $generator->generateUrlParams();
$actionParams = $generator->generateActionParams();
$actionParamComments = $generator->generateActionParamComments();
echo "<?php\n";
?>
namespace <?php
echo StringHelper::dirname(ltrim($generator->getControllerClass(), '\\'));
?>
;
use Yii;
use <?php
echo ltrim($generator->modelClass, '\\');
?>
;
<?php
if (!empty($generator->searchModelClass)) {
?>
use <?php
echo ltrim($generator->searchModelClass, '\\') . (isset($searchModelAlias) ? " as {$searchModelAlias}" : "");
?>
;
示例9: generate
public function generate()
{
if ($this->singularEntities) {
$this->modelClass = Inflector::singularize($this->modelClass);
$this->controllerClass = Inflector::singularize(substr($this->controllerClass, 0, strlen($this->controllerClass) - 10)) . 'Controller';
$this->searchModelClass = Inflector::singularize($this->searchModelClass);
}
$controllerFile = Yii::getAlias('@' . str_replace('\\', '/', ltrim($this->controllerClass, '\\')) . '.php');
$baseControllerFile = StringHelper::dirname($controllerFile) . '/base/' . StringHelper::basename($controllerFile);
$restControllerFile = StringHelper::dirname($controllerFile) . '/api/' . StringHelper::basename($controllerFile);
$files[] = new CodeFile($baseControllerFile, $this->render('controller.php'));
$params['controllerClassName'] = \yii\helpers\StringHelper::basename($this->controllerClass);
if ($this->overwriteControllerClass || !is_file($controllerFile)) {
$files[] = new CodeFile($controllerFile, $this->render('controller-extended.php', $params));
}
if ($this->overwriteRestControllerClass || !is_file($restControllerFile)) {
$files[] = new CodeFile($restControllerFile, $this->render('controller-rest.php', $params));
}
if (!empty($this->searchModelClass)) {
$searchModel = Yii::getAlias('@' . str_replace('\\', '/', ltrim($this->searchModelClass, '\\') . '.php'));
$files[] = new CodeFile($searchModel, $this->render('search.php'));
}
$viewPath = $this->getViewPath();
$templatePath = $this->getTemplatePath() . '/views';
foreach (scandir($templatePath) as $file) {
if (empty($this->searchModelClass) && $file === '_search.php') {
continue;
}
if (is_file($templatePath . '/' . $file) && pathinfo($file, PATHINFO_EXTENSION) === 'php') {
$files[] = new CodeFile("{$viewPath}/{$file}", $this->render("views/{$file}"));
}
}
return $files;
}
示例10: ltrim
/* @var $this yii\web\View */
/* @var $generator \infinitydevphp\gii\crud\Generator */
$modelClass = StringHelper::basename(ltrim(str_replace('/', '\\', $generator->reallySearchNs), '\\'));
$searchModelClass = StringHelper::basename($generator->reallySearchNs);
if ($modelClass === $searchModelClass) {
$modelAlias = $modelClass . 'Model';
}
$rules = $generator->generateSearchRules();
$labels = $generator->generateSearchLabels();
$searchAttributes = $generator->getSearchAttributes();
$searchConditions = $generator->generateSearchConditions();
echo "<?php\n";
?>
namespace <?php
echo StringHelper::dirname(str_replace('/', '\\', ltrim($generator->reallySearchNs, '\\')));
?>
;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use <?php
echo ltrim($generator->modelClass, '\\') . (isset($modelAlias) ? " as {$modelAlias}" : "");
?>
;
/**
* <?php
echo $searchModelClass;
?>
示例11: generate
public function generate()
{
$accessDefinitions = (require $this->getTemplatePath() . '/access_definition.php');
$this->controllerNs = \yii\helpers\StringHelper::dirname(ltrim($this->controllerClass, '\\'));
$this->moduleNs = \yii\helpers\StringHelper::dirname(ltrim($this->controllerNs, '\\'));
$controllerName = substr(\yii\helpers\StringHelper::basename($this->controllerClass), 0, -10);
if ($this->singularEntities) {
$this->modelClass = Inflector::singularize($this->modelClass);
$this->controllerClass = Inflector::singularize(substr($this->controllerClass, 0, strlen($this->controllerClass) - 10)) . 'Controller';
$this->searchModelClass = Inflector::singularize($this->searchModelClass);
}
$controllerFile = Yii::getAlias('@' . str_replace('\\', '/', ltrim($this->controllerClass, '\\')) . '.php');
$baseControllerFile = StringHelper::dirname($controllerFile) . '/base/' . StringHelper::basename($controllerFile);
$restControllerFile = StringHelper::dirname($controllerFile) . '/api/' . StringHelper::basename($controllerFile);
/*
* search generated migration and overwrite it or create new
*/
$migrationDir = StringHelper::dirname(StringHelper::dirname($controllerFile)) . '/migrations';
if (file_exists($migrationDir) && ($migrationDirFiles = glob($migrationDir . '/m*_' . $controllerName . '00_access.php'))) {
$this->migrationClass = pathinfo($migrationDirFiles[0], PATHINFO_FILENAME);
} else {
$this->migrationClass = 'm' . date('ymd_Hi') . '00_' . $controllerName . '_access';
}
$files[] = new CodeFile($baseControllerFile, $this->render('controller.php', ['accessDefinitions' => $accessDefinitions]));
$params['controllerClassName'] = \yii\helpers\StringHelper::basename($this->controllerClass);
if ($this->overwriteControllerClass || !is_file($controllerFile)) {
$files[] = new CodeFile($controllerFile, $this->render('controller-extended.php', $params));
}
if ($this->overwriteRestControllerClass || !is_file($restControllerFile)) {
$files[] = new CodeFile($restControllerFile, $this->render('controller-rest.php', $params));
}
if (!empty($this->searchModelClass)) {
$searchModel = Yii::getAlias('@' . str_replace('\\', '/', ltrim($this->searchModelClass, '\\') . '.php'));
if ($this->overwriteSearchModelClass || !is_file($searchModel)) {
$files[] = new CodeFile($searchModel, $this->render('search.php'));
}
}
$viewPath = $this->getViewPath();
$templatePath = $this->getTemplatePath() . '/views';
foreach (scandir($templatePath) as $file) {
if (empty($this->searchModelClass) && $file === '_search.php') {
continue;
}
if (is_file($templatePath . '/' . $file) && pathinfo($file, PATHINFO_EXTENSION) === 'php') {
echo $file;
$files[] = new CodeFile("{$viewPath}/{$file}", $this->render("views/{$file}", ['permisions' => $permisions]));
}
}
if ($this->generateAccessFilterMigrations) {
/*
* access migration
*/
$migrationFile = $migrationDir . '/' . $this->migrationClass . '.php';
//var_dump($migrationFile);exit;
$files[] = new CodeFile($migrationFile, $this->render('migration_access.php', ['accessDefinitions' => $accessDefinitions]));
/*
* access roles translation
*/
$forRoleTranslationFile = StringHelper::dirname(StringHelper::dirname($controllerFile)) . '/messages/for-translation/' . $controllerName . '.php';
$files[] = new CodeFile($forRoleTranslationFile, $this->render('roles-translation.php', ['accessDefinitions' => $accessDefinitions]));
}
/*
* create gii/[name]GiantCRUD.json with actual form data
*/
$suffix = str_replace(' ', '', $this->getName());
$controllerFileinfo = pathinfo($controllerFile);
$formDataFile = StringHelper::dirname(StringHelper::dirname($controllerFile)) . '/gii/' . str_replace('Controller', $suffix, $controllerFileinfo['filename']) . '.json';
//$formData = json_encode($this->getFormAttributesValues());
$formData = json_encode(SaveForm::getFormAttributesValues($this, $this->formAttributes()));
$files[] = new CodeFile($formDataFile, $formData);
return $files;
}
示例12: getChildNs
/**
* @return string The namespace for the child class which is used by the
* developers for non-automatically generated code.
*/
public function getChildNs()
{
return StringHelper::dirname($this->ns);
}
示例13: getNewMigrations
/**
* Returns the migrations that are not applied.
*
* @return array List of new migrations (key: migration version; value: alias)
*/
protected function getNewMigrations()
{
$applied = [];
foreach ($this->getMigrationHistory(null) as $version => $info) {
$applied[substr($version, 1, 13)] = true;
}
$moduleMigrations = FileHelper::findFiles(Yii::getAlias($this->modulesPath), ['only' => ['*/migrations/*php']]);
array_walk($moduleMigrations, function (&$value) {
$value = dirname($value);
});
$moduleMigrations = array_unique($moduleMigrations);
$directories = ArrayHelper::merge([$this->migrationPath], $moduleMigrations, $this->migrationLookup);
array_walk($directories, function (&$directory) {
$appPath = Yii::getAlias('@app');
// For correct detection on Windows
$vendorPath = StringHelper::dirname($appPath) . DIRECTORY_SEPARATOR . 'vendor';
$directory = str_replace($appPath, '@app', $directory);
$directory = str_replace($vendorPath, '@vendor', $directory);
$directory = FileHelper::normalizePath($directory, '/');
});
$migrations = [];
foreach ($directories as $alias) {
$dir = Yii::getAlias($alias);
$handle = opendir($dir);
while (($file = readdir($handle)) !== false) {
if ($file === '.' || $file === '..') {
continue;
}
$path = "{$dir}/{$file}";
if (preg_match('/^(m(\\d{6}_\\d{6})_.*?)\\.php$/', $file, $matches) && is_file($path) && !isset($applied[$matches[2]])) {
$migrations[$matches[1]] = $alias;
}
}
closedir($handle);
}
ksort($migrations);
return $migrations;
}
示例14: generateSearchModelCodeFile
/**
* 生成搜索模型代码文件
*
* @return CodeFile
* @throws \yii\base\InvalidConfigException
*/
protected function generateSearchModelCodeFile()
{
$currentFormModelFullClass = StringHelper::dirname($this->searchModelClass) . '\\' . StringHelper::basename($this->modelClass);
$isFormDirExistModel = class_exists($currentFormModelFullClass);
$searchModel = Yii::getAlias('@' . str_replace('\\', '/', ltrim($this->searchModelClass, '\\') . '.php'));
return new CodeFile($searchModel, $this->render('search.php', ['isFormDirExistModel' => $isFormDirExistModel]));
}
示例15: getNameSpace
public function getNameSpace()
{
$class = $this->modelClass;
return StringHelper::dirname($class);
}