Codeigniter 4 View file invalid - codeigniter-4

I am using codeigniter 4 with modules.I am getting error invalid file :Admin/valid_faq.php
What is wrong in the view path?
My Module structure is like below
app
--modules
-- Faq
--controller
--Models
--Views
--Admin
--view_faq
echo view('layout/header', $data);
echo view('layout/sidebar');
echo view('Admin/view_faq', $data);
echo view('layout/footer');
I have gave the full path then also it doesn't work.
echo view('App/Modules/Faq/Views/Admin/view_faq');
echo view('Modules/Faq/Views/Admin/view_faq');
I have added to Autoload as well
public $psr4 = [
APP_NAMESPACE => APPPATH, // For custom app namespace
'Config' => APPPATH . 'Config',
'Modules' => APPPATH . 'Modules',
];
When I checked the view file
SYSTEMPATH\Common.php : 1121 — CodeIgniter\View\View->render ( arguments )
F:\xampp\htdocs\modularcms\app\Config/../Views/Modules/Faq/Views/Admin/view_faq.php
This is working
echo view('../Modules/Faq/Views/Admin/view_faq', $data);
my view directory in the paths
public $viewDirectory = __DIR__ . '/../Views';
Error function
public static function renderer(string $viewPath = null, $config = null, bool $getShared = true)
{
if ($getShared)
{
return static::getSharedInstance('renderer', $viewPath, $config);
}
if (is_null($config))
{
$config = new \Config\View();
}
if (is_null($viewPath))
{
$paths = config('Paths');
$viewPath = $paths->viewDirectory;
}
return new \CodeIgniter\View\View($config, $viewPath, static::locator(), CI_DEBUG, static::logger());
}

I'm not clear about your modules directory. Let’s say you want to keep a simple Faq module that you can re-use between applications. You might create folder with name, faq, to store all of your modules within. You will put it right alongside your app directory in the main project root:
/faq // modules directory
/app
/public
/system
/tests
/writable
Open app/Config/Autoload.php and add the Faq namespace to the psr4 array property:
$psr4 = [
'Config' => APPPATH . 'Config',
APP_NAMESPACE => APPPATH, // For custom namespace
'App' => APPPATH, // To ensure filters, etc still found,
'Faq' => ROOTPATH.'faq'
];
A common directory structure within a module will mimic the main application folder:
/faq
/modules
/Config
/Controllers
/Database
/Helpers
/Language
/Libraries
/Models
/Views
/Admin
/view_faq
View:
echo view('Faq\Modules\Views\view_faq', $data);

It's probably already too late, but maybe others - like me - are looking for it. The solution was there for me:
Write the folder in the Views folder in lower case and put a double backslash behind it. So in your example:
echo view('Modules\Faq\Views\admin\\view_faq');

Related

Dom_munger issue with Node 7.7.3 - Path must be a string

I'm trying to update an application to support Node -v 7.7.3. But when I am running the grunt task dom_munger as per below:
dom_munger:{
read: {
options: {
read:[
{selector:'script[data-concat!="false"]',attribute:'src',writeto:'appjs', isPath: true},
{selector:'link[rel="stylesheet"][data-concat!="false"]',attribute:'href',writeto:'appcss'}
]
},
src: 'app/index.html'
}
}
I receive error:
Warning: Path must be a string. Received [ 'app/index.html' ] Use --force to continue.
I wonder if there is a way to rewrite above grunt task or if there might be a good alternative to dom_munger. Any help would be appreciated.
Per the grunt-dom-munger Github:
When isPath is true, the extracted values are assumed to be file
references and their path is made relative to the Gruntfile.js rather
than the file they're read from.
Try removing the isPath property, or altering it to match the path from your Gruntfile to the index.html file.
Remove isPath: true, and make sure that path in src attribute relative to the Gruntfile.js rather than the file they're read from.
If needs make a replace in path:
dom_munger: {
replacePath: {
options: {
callback: function($, file){
var scripts = $('script[data-concat!="false"]');
// NOTE: path is made relative to the Gruntfile.js rather than the file they're read from
for(var i=0, s, il=scripts.length; i<il; i++){
s = scripts[i];
if(s.attribs.src){
s.attribs.src = s.attribs.src.replace('../', '');
}
}
}
},
src: 'temp/index.html'
},
read: {
options: {
read: [
{selector:'script[data-concat!="false"]',attribute:'src',writeto:'appjs'},
{selector:'link[rel="stylesheet"][data-concat!="false"]',attribute:'href',writeto:'appcss'}
]
},
src: 'temp/index.html'
}
}
Thanks you! But this only seems to work if the Grunt and Index are in the same folder structure. My structure looks like this:
- /app
-index.html
- gruntfile.js
And without the attribute 'isPath' the dom_munger will look for js files in the same directory as where the Gruntfile is places.

Folder copy including files in gulp

I'm trying to copy 2 folders onto a single build folder and for the second path I want to copy whole libs folder including libs folder itself to destination.
var paths = {
'standalone' : '../app-ui/assets/js',
'standalone_libs' : '../app-ui/libs',
'destination' : '../SomeFolder'
}
gulp.task('folder-copy', function() {
return gulp.src([paths.standalone_js + '/*', paths.standalone_libs + '/*']).pipe(gulp.dest(paths.destination));
});
Structure according to code
->SomeFolder
->app.js [ file from ../app-ui/assets/js ]
-> angular/angular.js [ file from ../app-ui/libs ]
-> lodash/lodash.js [ file from ../app-ui/libs ]
Actual Structure wanted
->SomeFolder
->app.js [ file from ../app-ui/assets/js ]
-> libs
-> angular/angular.js [ file from ../app-ui/libs ]
-> lodash/lodash.js [ file from ../app-ui/libs ]
You could specify the base in gulp.src :
return gulp.src(['some/path/app/*', 'libs/**/*'], {base: '.'})
.pipe(gulp.dest('build'));
This will copy all your files in libs, with the directory structure intact. But the directory structure will be preserved for app.js also...
I would just do two separate copy.
You can use merge-stream. There's a recipe in gulp repository. It would boil down to something like this :
var merge = require('merge-stream')
var libs= gulp.src('libs/**/*', {base: '.'})
.pipe(gulp.dest('build'));
var app = gulp.src('app.js')
.pipe(gulp.dest('build'));
return merge(libs, app);
Try removing the /* because this means the whole content inside the folder is what you want.
So for the libs, I would not add the /* like follows
return gulp.src([paths.standalone_js + '/*', paths.standalone_libs ]).pipe(gulp.dest(paths.destination));
What about changing this:
var paths = {
'standalone' : '../app-ui/assets/js',
'standalone_libs' : '../app-ui/libs',
'destination' : '../SomeFolder'
}
to this:
var paths = {
'standalone' : '../app-ui/assets/js',
'standalone_libs' : '../app-ui/(libs)',
'destination' : '../SomeFolder'
}

How to get baseUrl in Yii2 advanced app after Url rewrite

I have used Yii2 advanced application. i rewrite url in frontend and backend.
After rewrite Frontend url is
localhost:83/Working-copy/mySite/
And For Backend
localhost:83/Working-copy/mySite/admin
Now i want to get base url like
/Working-copy/mySite/
But i don't get it properly
I have tried following ways,
echo Yii::getAlias('#web') // ans= /Working-copy/mySite/admin
echo Yii::getAlias('#backend') // ans= /var/www/Working-copy/mySite/backend
echo Yii::getAlias('#webroot') // ans= /var/www/Working-copy/mySite/backend
echo Yii::$app->request->BaseUrl // ans= /Working-copy/mySite/admin
echo Yii::$app->getBasePath(false) // ans= /var/www/Working-copy/mySite/backend
echo Yii::$app->homeUrl // ans = /Working-copy/mySite/admin/
In some url i get /var/www/ and in some url get /admin/.
i only want my project name.
any solution please?
Create components into common folder.
Add Request.php
namespace common\components;
class Request extends \yii\web\Request {
public $web;
public $adminUrl;
public function getBaseUrl(){
return str_replace($this->web, "", parent::getBaseUrl()) . $this->adminUrl;
}
public function getActualBaseUrl(){
return str_replace($this->web, "", parent::getBaseUrl());
}
public function resolvePathInfo(){
if($this->getUrl() === $this->adminUrl){
return "";
}else{
return parent::resolvePathInfo();
}
}
}
Use Yii::$app->request->getActualBaseUrl().

downloading files as a corrupted files in kohana

hi guys i'm facing problem with file upload and download in kohana
my controller is like this:
class Controller_Test extends Controller
{
public function action_display()
{
$type = $_FILES['file']['type'];
switch ($type)
{
case 'image/gif':
$otype='.gif'; break;
case 'image/jpeg':
case 'image/pjpeg':
$otype= '.jpg'; break;
case 'image/png':
$otype= '.png'; break;
case 'application/octet-stream':
$otype='.doc'; break;
case 'txt': $otype='.txt'; break;
case 'application/pdf': $otype='.pdf'; break;
}
//rename the file
$name = time() . '_' . mt_rand(1000,9999).$otype;
$directory = $_SERVER['DOCUMENT_ROOT'].URL::base().'media';
//uploading a file
$filename = Upload::save($_FILES['file'], $name, $directory);
$this->auto_render = false;
$this->response->send_file($filename);
}//action
}//controller
when i call this function file uploaded fine
but downloading file as a corrupted file
help me how to solve this..
thanks in advance.
You shouldn't add URL::base() inside the path name as that could add something like "http://..." inside the file path. Try removing URL::base() and try again.
To start, there's some simple debug checks you can do here.
Is $directory valid?
is $filename a valid file path, or is it FALSE? (See http://kohanaframework.org/3.2/guide/api/Upload#save)
I'm going to assume $directory is invalid.
You want to use the absolute path constants to build directory paths. Instead of using $_SERVER['DOCUMENT_ROOT'].URL::base() (which is wrong in any case)
Rather use APPPATH or DOCROOT, eg $directory = APPPATH.'media'; see https://github.com/kohana/kohana/blob/3.2/master/index.php#L57-74

Drupal 6 File Handling

I am handling file upload field in a form using Drupal 6 form APIs. The file field is marked as required.
I am doing all the right steps in order to save and rename files in proper locations.
upload form
$form = array();
....
$form['image'] = array(
'#type' => 'file',
'#title' => t('Upload photo'),
'#size' => 30,
'#required' => TRUE,
);
$form['#attributes'] = array('enctype' => "multipart/form-data");
...
form validate handler
$image_field = 'image';
if (isset($_FILES['files']) && is_uploaded_file($_FILES['files']['tmp_name'][$image_field])) {
$file = file_save_upload($image_field);
if (!$file) {
form_set_error($image_field, t('Error uploading file'));
return;
}
$files_dir = file_directory_path();
$contest_dir = 'contest';
if(!file_exists($files_dir . '/' . $contest_dir) || !is_dir($files_dir . '/' . $contest_dir))
mkdir($files_dir . '/' . $contest_dir);
//HOW TO PASS $file OBJECT TO SUBMIT HANDLER
$form_state['values'][$image_field] = $file;
file_move($form_state['values'][$image_field], $files_dir."/" . $contest_dir . "/contest-". $values['email']. "-" . $file->filename);
}
else {
form_set_error($image_field, 'Error uploading file.');
return;
}
On submiting form
Form always reports an error Upload photo field is required. although files are getting uploaded. How to deal with this issue?
How to pass file information to submit handler?
your handler is wrong. You never should touch $_FILES or $_POST variables in drupal, instead you should only use the drupal tools. Said that, the implementation you should is like that:
function my_form_handler(&$form,&$form_state){/** VALIDATION FILE * */
$extensions = 'jpeg jpg gif tiff';
$size_limit = file_upload_max_size();
$validators = array(
'my_file_validate_extensions' => array($extensions),
'my_file_validate_size' => array($size_limit),
);
$dest = file_directory_path();
if ($file = file_save_upload('image', $validators, $dest)) {
//at this point your file is uploaded, moved in the files folder and saved in the DB table files
}
}
I think you'll want to use the filefield module and append it to a form, as described in:
Drupal Imagfield/Filefield in custom form
The question has a link to the solution:
http://sysadminsjourney.com/content/2010/01/26/display-cck-filefield-or-imagefield-upload-widget-your-own-custom-form
From the Drupal 6 Form API docs:
"Note: the #required property is not supported (setting it to true will always cause a validation error). Instead, you may want to use your own validation function to do checks on the $_FILES array with #required set to false. You will also have to add your own required asterisk if you would like one."
Old post, but I'm looking for something similar and figured I add that.

Resources