Comments (4)
I did this but its still not working for me
from admin.
BootstrapFormHelper.php - when creates a form don't sets enctype to "multipart/form-data", because of bug in create method.
Changing $Model->displayFieldTypes[$modelKey] to $Model->displayFieldTypes should help.
Here are the complete create method of BootstrapFormHelper class.
public function create($model = null, $options = array())
{
if (empty($options['class'])) {
$options['class'] = 'well';
}
$modelKey = $this->model();
$Model = ClassRegistry::init($modelKey);
if(!empty($Model->displayFieldTypes)){
if(in_array('image', $Model->displayFieldTypes) || in_array('file',$Model->displayFieldTypes)){
$type_val = array(
'type' => 'file'
);
$options = array_merge($type_val, $options);
}
}
return parent::create($model, $options);
}
Don't forget to set models field type to image (or file) in Models class file.
Like that :
var $displayFieldTypes = array(
'src_big' => 'image'
);
var $upLoads = array(
'imgDir' => 'photos'
);
from admin.
hello,
This is not copying the image inside the correct folder, after a creation of new line, you can see (image not found)
from admin.
NOW is working for my,
I changed the AdminAppController.php with this:
/**********************************************************************************************************************
array( 'className' => 'Admin.BootstrapForm' ), 'Html', 'Session' => array( 'className' => 'Admin.BootstrapSession' ), 'Paginator' => array( 'className' => 'Admin.BootstrapPaginator' ) ); ``` // Check if they are logged in function authenticate() { // Check if the session variable User exists, redirect to loginform if not if(!$this->Session->check('User')) { $this->redirect(array('controller' => 'users', 'action' => 'login_form')); exit(); } } // Authenticate on every action, except the login form function afterFilter() { if( $this->action != 'login_form' ) { $this->authenticate(); } } /** * Scaffold * * @var string */ public $scaffold; /** * Pagination * * @var string */ public function beforeRender() { } /** * Before Filter * * @return void */ public function beforeFilter() { $modelClass = $this->modelClass; // $fieldKey = $this->field(); $Model = ClassRegistry::init($modelClass); $ignoreModelList = array(); if(isset($Model->ignoreModelList)){ $ignoreModelList = $Model->ignoreModelList; } $displayFieldTypes[$modelClass] = array(); if(isset($Model->displayFieldTypes)){ $displayFieldTypes[$modelClass] = $Model->displayFieldTypes; } // Get association model displayfield types foreach ($Model->hasMany as $key => $value) { $subModel = ClassRegistry::init($value['className']); $displayFieldTypes[$key] = $subModel->displayFieldTypes; } $ignoreFieldList = array(); if(isset($Model->ignoreFieldList)){ $ignoreFieldList = $Model->ignoreFieldList; } $adminSettings = array(); if(isset($Model->adminSettings)){ $adminSettings = $Model->adminSettings; } parent::beforeFilter(); $iconPath = APP.'Plugin'.DS.'Admin'.DS.'webroot'.DS.'img'.DS.'admin_icons'; $iconFolder = new Folder($iconPath); $iconsInFolder = $iconFolder->find('.*png', true); foreach ($iconsInFolder as $key => $value) { $iconsInFolder[$key] = str_replace('.png', '', $value); } $Folder = new Folder(APP . 'Model'); $files = $Folder->find('.*\.php', true); $navbar = array(); foreach ($files as $file) { if ($file !== 'AppModel.php') { $model = str_replace('.php', '', $file); $Model = ClassRegistry::init($model); $schema = $Model->schema(); if(!in_array($model, $ignoreModelList) && isset($schema)){ if(isset($Model->adminSettings['icon'])){ $icon_file = $iconPath.DS.$Model->adminSettings['icon'].'.png'; if(file_exists($icon_file)){ $icon = $Model->adminSettings['icon']; } else { $icon = $iconsInFolder[0]; array_shift($iconsInFolder); } } else { $icon = $iconsInFolder[0]; array_shift($iconsInFolder); } $controller = Inflector::tableize($model); $title = Inflector::pluralize($model); $navbar[] = array( 'title' => $title, 'url' => array( 'plugin' => 'admin', 'controller' => $controller, 'action' => 'index', ), 'icon' => $icon, ); } } } $request = $this->request; $data=$request['data']; if($data){ $Model = ClassRegistry::init($modelClass); $imgDir = $Model->upLoads['imgDir']; foreach ($request['data'][$modelClass] as $key => $value) { if(isset($displayFieldTypes[$modelClass][$key]) && $displayFieldTypes[$modelClass][$key] == 'file' || $displayFieldTypes[$modelClass][$key] == 'image'){ if(empty($value)){ unset($this->request->$request['data'][$modelClass][$displayFieldTypes[$modelClass]]); } else { $itemDir = ''; if(isset($Model->upLoads['itemDir']) && !empty($Model->upLoads['itemDir'])){ // set as a field value or as a string in model $upLoads variable $itemDir = $Model->upLoads['itemDir']; if(is_array($itemDir) && isset($itemDir['field'])) { $itemField = $itemDir['field']; if(isset($data[$modelClass][$itemField])){ $itemDir = $data[$modelClass][$itemField]; } } else { $itemDir = $Model->upLoads['itemDir']; } } $fileOK = $this->uploadFiles($imgDir, $value, $itemDir); if(array_key_exists('urls', $fileOK)) { // save the url in the form data $this->request->data[$modelClass][$key] = $fileOK['urls'][0]; } } } } } if(empty($ignoreFieldList)) $ignoreFieldList = array(); if(empty($displayFieldTypes)) $displayFieldTypes = array(); if(empty($ignoreModelList)) $ignoreModelList = array(); if(empty($adminSettings)) $adminSettings = array(); $this->set(compact('navbar','displayFieldTypes','ignoreFieldList', 'adminSettings')); } /** * uploads files * @return: * will return an array with the success of each file upload */ public function uploadFiles($folder=null, $formdata, $itemId = null) { // setup dir names absolute and relative if(isset($folder)){ $folder_url = WWW_ROOT.'img'.DS.$folder; $rel_url = 'img'.DS.$folder; } else { $folder_url = WWW_ROOT.'img'; $rel_url = 'img'; } // create the folder if it does not exist if(!is_dir($folder_url)) { mkdir($folder_url); } // if itemId is set create an item/sub folder if($itemId) { // set new absolute folder $folder_url = $folder_url.DS.$itemId; // set new relative folder $rel_url = $rel_url.DS.$itemId; // create the folder if it does not exist if(!is_dir($folder_url)) { mkdir($folder_url); } } // list of permitted file types $permitted = array('image/gif','image/jpeg','image/pjpeg','image/png'); // replace spaces with underscores // $filename = $formdata; // $filename = substr($filename,strpos($filename,'.')+1,strlen($filename)); $filename = $formdata['name']; $filename = str_replace(' ', '_', $filename); // assume filetype is false $typeOK = FALSE; // check filetype is ok foreach($permitted as $type) { if($type == $formdata['type']) { $typeOK = TRUE; break; } } if($typeOK) { if(!file_exists($folder_url.DS.$filename)) { // create full filename $full_url = $folder_url.DS.$filename; $url = $rel_url.DS.$filename; // upload the file $success = move_uploaded_file($formdata['tmp_name'], $full_url); } else { // create unique filename and upload file // ini_set('date.timezone', 'India/Maldives'); $now = date('Y-m-d-His'); $full_url = $folder_url.DS.$now.$filename; $url = $rel_url.DS.$now.$filename; $success = move_uploaded_file($formdata['tmp_name'], $url); } // if upload was successful if($success) { // save the url of the file $result['urls'][] = substr($url, 4); } else { $result['errors'][] = "Error uploaded $filename. Please try again."; } } elseif($formdata['error'] == 4) { // no file was selected for upload $result['nofiles'][] = "No file Selected"; } else { // unacceptable file type $result['errors'][] = "$filename cannot be uploaded. Acceptable file types: gif, jpg, png."; } return $result; } } ``` *////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// and the form.ctp in the line 40 BSForm->create($modelClass, array('type' => 'file')); ?>I Hope this help you too,
Neiklot
from admin.
Related Issues (20)
- Change user password HOT 1
- Admin panel not displaying correctly HOT 18
- Changing the View elements HOT 2
- Bootstrap CSS link is incorrect
- Logout problem
- Error when add new users HOT 2
- how can upload PDF file HOT 2
- Checkbox and Combobox
- navbar is returning empty forever HOT 1
- Conditions are not considered in admin panel. HOT 1
- Error: AdminController could not be found. HOT 1
- Different Area for different Group
- Admin layout is not working
- Regarding setup of Admin Panel HOT 3
- Issue when: App model -> hasMany -> plugin model
- Collision with debug_kit plugin
- Incompatible with Plugins Behavior HOT 1
- Table for model was not found in datasource default. HOT 9
- Error: Call to a member function check() on a non-object HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from admin.