Reputation: 63
I have a table named Userprofile in the backend which saves the user information including profile image Yii::$app->params['uploadPath'] = Yii::$app->basePath . '/web/avatar/'; but when i tried to used the same table from the frontend then the image is saved in the frontend as i have used basePath. How can i save the profile pic in same folder and can do CRUD operation from frontend as well as backend?
Upvotes: 2
Views: 945
Reputation: 1621
- configuration with migration . folder path: common\config\main-local.php
- create table: client
CREATE TABLE `client` (
`client_id` int NOT NULL AUTO_INCREMENT ,
`first_name` varchar(255) NOT NULL ,
`middle_name` varchar(255) NULL ,
`last_name` varchar(255) NOT NULL ,
PRIMARY KEY (`client_id`)
);
- go to backend gii example: http://backend.dev/gii
Upvotes: 0
Reputation: 31
suppose you want to save all images for (frontend and backend) CRUD
under frontend/web/uploads
so in your backend config file
add this component:
'urlManagerFrontEnd' => [
'class' => 'yii\web\urlManager',
'baseUrl' => 'http://front.domain.ext/',//frontend app url
],
then use it from the backend controllers or models :
Yii::$app->urlManagerFrontEnd->baseUrl ."/path/to/your/place";
Hope this help
Upvotes: 0
Reputation: 133400
If you need simply render the related views using alias eg:
if you want use a backend view from front end
class YourControllerController extends Controller
{
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
];
}
public function actionIndex()
{
$searchModel = new YourModelSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$dataProvider->pagination->pageSize=15;
return $this->render('@backend/views/your-controller/index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
Upvotes: 1